Hi,
In both examples below, the expected results are observed. However,in the second example (class Bar) warnings are generated. This isRuby 1.8.2 on Mac Os x 10.4.7.
I wonder if someone might be able to enlighten me?
Chris
class Foo def initialize(&proc) meta = class << self; self; end meta.send(:define_method, :bar, &proc) endend
foo = Foo.new { false }puts foo.bar #=> falsefoo = Foo.new { 'hello world' }puts foo.bar #=> hello_world
class Bar def initialize(&proc) class << self define_method(:foo, &proc) end endend
bar = Bar.new { false }#=> warning: tried to create Proc object without a blockputs bar.foo #=> falsebar = Bar.new { 'hello_world' }#=> warning: tried to create Proc object without a blockputs bar.foo #=> hello_world