summaryrefslogtreecommitdiff
path: root/sample/evaldef.rb
blob: a705300a940b029924e511719fcb830248449fe5 (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
# method definition by eval()
# output:
#	bar
#	(eval):26: method `baz' not available for "#<foo: 0xbfc5c>"(foo)

class Foo
  def foo
    eval("
def baz
  print(\"bar\n\")
end")
  end
end

class Bar : Foo
  def bar
    baz()
  end
end

f = foo.new
b = bar.new

b.foo
b.bar
f.baz