Skip to content

Instantly share code, notes, and snippets.

@micahboyd
Created June 27, 2018 05:46
Show Gist options
  • Select an option

  • Save micahboyd/86e6c46795a15abeab92ae9911d72c34 to your computer and use it in GitHub Desktop.

Select an option

Save micahboyd/86e6c46795a15abeab92ae9911d72c34 to your computer and use it in GitHub Desktop.
Ruby method lambda?
# lambda way
adder = -> (x,y) { x + y }
math = -> (fn, x, y) { fn.(x,y) }
math.(adder, 1, 2) # => 3
# method lambda??
adder = method def adder(x,y)
x + y
end
math = method def math(fn, x, y)
fn.(x,y)
end
math(adder, 1, 2) # => 3!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment