Hi,
Consider this code
module Foo
end
def do_stuff_to_foo(&block)
Foo.module_eval &block
end
do_stuff_to_foo {def greeting; 'hello'; end}
If you paste this into irb on 1.9 (r14600, compiled a few minutes ago)
the greeting method is not added to Foo, but to the top level.
On 1.8 it's added to Foo, as I would expect.
Is this change intentional ? I haven't been able to find anything
written about it. I've had a quick scan back through the source and
this isn't a particularly recent change - r11500 exhibits the same
behaviour. I'd be curious to hear the rationale if this is indeed
intentional
Fred
on 24.12.2007 12:30
on 24.12.2007 12:39
Hi, Frederick Cheung wrote: > > do_stuff_to_foo {def greeting; 'hello'; end} > > If you paste this into irb on 1.9 (r14600, compiled a few minutes ago) > the greeting method is not added to Foo, but to the top level. > On 1.8 it's added to Foo, as I would expect. > > Is this change intentional ? I haven't been able to find anything > written about it. I've had a quick scan back through the source and this > isn't a particularly recent change - r11500 exhibits the same behaviour. > I'd be curious to hear the rationale if this is indeed intentional This is a bug. If you write a block in method do_stuff_to_foo directly, it's work fine. I'll fix it.
on 24.12.2007 12:42
Frederick Cheung wrote: > > If you paste this into irb on 1.9 (r14600, compiled a few minutes ago) > the greeting method is not added to Foo, but to the top level. > On 1.8 it's added to Foo, as I would expect. even more strange, this works as expected: module Foo end Foo.module_eval { def greeting; 'hello'; end } Foo.instance_methods # => [:greeting] [murphy]
on 24.12.2007 12:43
On 24 Dec 2007, at 11:39, SASADA Koichi wrote: > directly, it's work fine. I'll fix it. > Cool. Thanks! Fred
on 01.01.2008 04:58
SASADA Koichi wrote (2007-12-24): > This is a bug. If you write a block in method do_stuff_to_foo > directly, it's work fine. I'll fix it. Any progress? It seems to be the last thing that makes Rails tests fail. [murphy]
on 03.01.2008 09:30
Hi, Kornelius Kalnbach wrote: > SASADA Koichi wrote (2007-12-24): >> This is a bug. If you write a block in method do_stuff_to_foo >> directly, it's work fine. I'll fix it. > Any progress? It seems to be the last thing that makes Rails tests fail. I wrote [ruby-core:14716] about it. I can't make it on time of last release.