Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created August 19, 2015 21:35
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 JoshCheek/422ca40091f1995ddcc3 to your computer and use it in GitHub Desktop.
Save JoshCheek/422ca40091f1995ddcc3 to your computer and use it in GitHub Desktop.
All the syntaxes I can think of offhand for lambdas / blocks
# ----- Lambda -----
# the syntax for a lambda: stabby arrow
-> a { a + a }
# ----- Block -----
# the two literal syntaxes for a block, + syntax to place lambda into block slot
lambda { |a| a + a }
lambda do |a| a + a end
lambda &->(a) { a + a }
# ----- Parens are optional -----
->(a) { a + a }
lambda() { |a| a + a }
lambda() do |a|
a + a
end
l = ->(a) { a + a }
lambda(&l)
# ----- Lambda with both block literal syntaxes -----
-> a { a + a }
-> a do
a + a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment