From: Morton Goldberg Date: 2006-07-18T22:56:53+09:00 Subject: Re: Strange behaviour - Instantiating an object and giving it a block to be used as a method body Thanks for pointing this out. I did indeed miss an important point. Regards, Morton On Jul 18, 2006, at 9:18 AM, ts wrote: >>>>>> "M" == Morton Goldberg writes: > > M> # Each instance will have its own version of method "bar". > > no, not really > > moulon% cat b.rb > #!/usr/bin/ruby > class Foo > > def Foo.make_bar(&block) > define_method(:bar, &block) > end > > # Each instance will have its own version of method "bar". > def initialize(&block) > Foo.make_bar(&block) > end > > end > > f = Foo.new {puts "foobar"} > f.bar > Foo.new {|s| printf "%s %s\n", s, s}.bar("foobar") > f.bar("xxxxx") > moulon% > > moulon% ./b.rb > foobar > foobar foobar > xxxxx xxxxx > moulon% > > > Guy Decoux >