Project

General

Profile

Actions

Bug #5914

closed

Calling extend with an anonymous module requires use of parentheses

Added by Spakman (Mark Somerville) about 12 years ago. Updated about 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
2.0.0dev
Backport:
[ruby-core:42189]

Description

=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


Files

noname (855 Bytes) noname Spakman (Mark Somerville), 01/20/2012 09:29 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0