Skip to content

Instantly share code, notes, and snippets.

@cstorey
Last active December 14, 2015 18:29
Show Gist options
  • Save cstorey/5129666 to your computer and use it in GitHub Desktop.
Save cstorey/5129666 to your computer and use it in GitHub Desktop.
Ruby's rather non-deductive behavior difference between lambdas / procs. (Edited for coherency).
1.9.3p0 :004 > require 'pp'
=> true
1.9.3p0 :002 > p = proc { |a| pp proc_args: a }
=> #<Proc:0x0000010090b838@(irb):2>
1.9.3p0 :010 > p.call(1,2)
{:proc_args=>1}
1.9.3p0 :008 > stabby = ->(a) { pp stabby_args: a }
=> #<Proc:0x00000101099410@(irb):8 (lambda)>
1.9.3p0 :009 > stabby.call(1,2)
ArgumentError: wrong number of arguments (2 for 1)
from (irb):8:in `block in irb_binding'
from (irb):9:in `call'
from (irb):9
from /Users/cez/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'
1.9.3p0 :011 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment