From: "Юрий Соколов" Date: 2012-01-20T20:52:08+09:00 Subject: [ruby-core:42190] Re: [ruby-trunk - Bug #5914][Open] Calling extend with an anonymous module requires use of parentheses --f46d0447887768f5b104b6f44f02 Content-Type: text/plain; charset=ISO-8859-1 When you call without parentheses, then block `do` is going to `extend` method, but not `Module.new` 2012/1/20 Mark Somerville > > Issue #5914 has been reported by Mark Somerville. > > ---------------------------------------- > Bug #5914: Calling extend with an anonymous module requires use of > parentheses > https://bugs.ruby-lang.org/issues/5914 > > Author: Mark Somerville > Status: Open > Priority: Normal > Assignee: > Category: > Target version: > ruby -v: 2.0.0dev > > > =begin > > Given Ruby 2.0.0dev, 1.9.3 or 1.8.7 and this code: > > class Dude > def initialize > extend Module.new do > def hello > puts "Word!" > end > end > end > end > > Dude.new.hello > > No warning is given, but it does not behave how I expect and throws a > NoMethodError. > > However, if parentheses are used on the call to extend, things behave as > expected: > > class Dude > def initialize > extend(Module.new do > def hello > puts "Word!" > end > end) > end > end > > Dude.new.hello > => Word! > > I don't understand what is happening in the first case (without > parentheses). Is this a bug or a misunderstanding on my part? > > =end > > > -- > http://bugs.ruby-lang.org/ > > --f46d0447887768f5b104b6f44f02 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable When you call without parentheses, then block `do` is going to `extend` met= hod, but not `Module.new`

2012/1/20 Mark = Somerville <mark@scottishclimbs.com>

Issue #5914 has been reported by Mark Somerville.

----------------------------------------
Bug #5914: Calling extend with an anonymous module requires use of parenthe= ses
https:= //bugs.ruby-lang.org/issues/5914

Author: Mark Somerville
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 2.0.0dev


=3Dbegin

Given Ruby 2.0.0dev, 1.9.3 or 1.8.7 and this code:

=A0class Dude
=A0 =A0def initialize
=A0 =A0 =A0extend Module.new do
=A0 =A0 =A0 =A0def hello
=A0 =A0 =A0 =A0 =A0puts "Word!"
=A0 =A0 =A0 =A0end
=A0 =A0 =A0end
=A0 =A0end
=A0end

=A0Dude.new.hello

No warning is given, but it does not behave how I expect and throws a NoMet= hodError.

However, if parentheses are used on the call to extend, things behave as ex= pected:

=A0class Dude
=A0 =A0def initialize
=A0 =A0 =A0extend(Module.new do
=A0 =A0 =A0 =A0def hello
=A0 =A0 =A0 =A0 =A0puts "Word!"
=A0 =A0 =A0 =A0end
=A0 =A0 =A0end)
=A0 =A0end
=A0end

=A0Dude.new.hello
=A0=3D> Word!

I don't understand what is happening in the first case (without parenth= eses). Is this a bug or a misunderstanding on my part?

=3Dend


--
http://bugs.ruby-l= ang.org/


--f46d0447887768f5b104b6f44f02--