Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Foo
include Module.new {
def this_works
end
}
include Module.new do
def this_doesnt_work
end
end
end
foo = Foo.new
foo.this_works
foo.this_doesnt_work
@jcoglan

This comment has been minimized.

Copy link

@jcoglan jcoglan commented Oct 12, 2012

The second example is parsed like this:

include(Module.new) do
  def this_doesnt_work
  end
end

That is, the block is an argument to include, not to Module.new.

@localshred

This comment has been minimized.

Copy link

@localshred localshred commented Oct 12, 2012

It's failing because the block precedence is being applied wrongly in the first. The block is being consumed by include in one case and Module.new in the other.

@brixen

This comment has been minimized.

Copy link

@brixen brixen commented Oct 12, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.