Skip to content

Instantly share code, notes, and snippets.

@JonRowe
Created July 17, 2013 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonRowe/6016855 to your computer and use it in GitHub Desktop.
Save JonRowe/6016855 to your computer and use it in GitHub Desktop.
class Thing
def [] a, &block
block.call a
end
end
thing = Thing.new
# explicit works fine
thing[:a,&(-> a { puts a })]
# implicit won't even parse
# thing[:a] { |a| puts a }
@runlevel5
Copy link

There is nothing wrong with the syntax, it is just that Ruby19 does not support this correctly yet (ref http://nuclearsquid.com/writings/ruby-1-9-what-s-new-what-s-changed/)

I'd rewrite it to:

def [] a
  yield a if block_given?
end

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