From: Frederick Cheung Date: 2007-12-26T06:49:05+09:00 Subject: Re: module_eval differences between 1.8 & 1.9 On 25 Dec 2007, at 21:35, MonkeeSage wrote: > > Played with this a bit today. It seems that #module_eval creates a > private instance method *and* a class method on module Foo, and also > creates a private instance method on main. And, as you noted, the > method is not listed under #instance_methods (or > #private_instance_methods for that matter; it's listed in > #private_methods). This seems really wrong to me (at the very least, > the block version should be consistent with the string version). > The private method stuff is a red herring - that's how things get added to the top level. Over on ruby-core Sasada Koichi said that he would fix it. Fred > Here is the example, expanded to demonstrate what I'm referring to: > > module Foo; end > class Bar; include Foo; end > > def do_stuff_to_foo(&b) > Foo.module_eval &b > end > > do_stuff_to_foo {def greet; "hello"; end} > > p Foo.send(:greet) # => "hello" > p Bar.send(:greet) # => "hello" > p Bar.new.send(:greet) # => "hello" > p self.private_methods.include? :greet # => true > > Ps. #module_exec is also broken like this. > > Regards, > Jordan >