summaryrefslogtreecommitdiff
path: root/sample/tt.rb
blob: 4afa2022e6a1175679a0ee340067b080395e92c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
module Print
  print("in Print\n")
  def println(*args)
    for a in args
      print(a)
    end
    print("\n")
  end

  def println2(*args)
    print(*args)
    print("\n")
  end
end

module Print2
  def println(*args)
    print("pr2: ");
    super
  end
end

module Print3
  include Print2
  def println(*args)
    print("pr3: ");
    super
  end
end

include Print, Print2, Print3

println2("in TopLevel")

print("a: ", $OPT_test, "\n")
printf("%10.5g: %*s -> 0x%x\n", 123345, -10, Print, Print.id);

println("a+ matches aaa at ", "bccAAaaa" =~ /a+/)
ttt = "this is a  "
if offset = (ttt =~ /this ([^ ]*) (.*)/)
  println("0 = ", $&);
  println("1 = ", $1);
  println("2 = ", $2);
end

class Fib : Object
  print("in Fib:Object\n")

  def Fib.test(*args)
    println("in Fib.test")

    if args; println(*args) end
    args = args.grep(/^c/)
    super(*args)
  end

  def init
    println("in Fib.init");
  end

  def fib(n)
    a =0; b = 1

    while b <= n
      c = a; a = b; b = c+b
    end
    return b
  end
end

def Object.test(*args)
  println("in Object.test")
  if args; println(*args) end
end

Fib.test("abc", "def", "aaa", "ccc")
println("1:", 0x3fffffffa)
println("2:", 0x3ffffffa)
#println("3:", 0x40000000+0x40000000)

fib = Fib.new

fib.init
print(Fib, ":")

#for i in 1 .. 100
#  fib.fib(90000)
#end

println(fib.fib(9000))

def tt
  for i in 1..10
    println("i:", i);
    yield(i);
  end
end

test = tt() {i|break if i == 2}
println([1,2,3,4].join(":"))