Skip to content

Instantly share code, notes, and snippets.

@styx
Forked from bbugh/gist:3909614
Last active August 29, 2015 14:17
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 styx/e566ed83ce8f7cc91db9 to your computer and use it in GitHub Desktop.
Save styx/e566ed83ce8f7cc91db9 to your computer and use it in GitHub Desktop.

In addition to Kevin Conner's answer: block arguments do not support the same semantics as method arguments. You cannot define default arguments or block arguments.

This is only fixed in Ruby 1.9 with the new alternative "stabby lambda" syntax which supports full method argument semantics.

http://stackoverflow.com/questions/89650/how-do-you-pass-arguments-to-define-method#answer-109379

Example:

# Works
def meth(default = :foo, *splat, &block) puts 'Bar'; end

# Doesn't work
define_method :meth { |default = :foo, *splat, &block| puts 'Bar' }

# This works in Ruby 1.9 (modulo typos, I don't actually have it installed)
define_method :meth, ->(default = :foo, *splat, &block) { puts 'Bar' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment