Skip to content

Instantly share code, notes, and snippets.

@jstorimer
Created October 12, 2012 20:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstorimer/3881340 to your computer and use it in GitHub Desktop.
Save jstorimer/3881340 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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
Copy link

brixen commented Oct 12, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment