Skip to content

Instantly share code, notes, and snippets.

@mrflip
Created August 24, 2008 08:39
Show Gist options
  • Save mrflip/6974 to your computer and use it in GitHub Desktop.
Save mrflip/6974 to your computer and use it in GitHub Desktop.
# this works
a = lambda{ |b| b*3 }
# => #<Proc:0x01f5f540@(irb):125>
a.call 4
# => 12
# strangely, this does too (with a warning)
a.call 4, 6
# (irb):125: warning: multiple values for a block parameter (2 for 1)
# from (irb):131
# => [4, 6, 4, 6, 4, 6]
# but this doesn't -- you need at least the one argument.
a.call
# (irb):133: warning: multiple values for a block parameter (0 for 1)
# from (irb):134
# NoMethodError: You have a nil object when you didn't expect it!
# You might have expected an instance of Array.
# The error occurred while evaluating nil.*
# from (irb):133
# from (irb):134:in `call'
# from (irb):134
# from :0
# compare:
a = lambda{ |*b| (b.first||23)*3 }
# => #<Proc:0x01f3fa38@(irb):135>
a.call 4
# => 12
a.call # can call with no args now
# => 69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment