haml - what does ruby symbol -> do? -
this question has answer here:
options_from_collection_for_select(['all'], 'to_s', -> (input) { t("admin.mystring") })
i found line of code in haml file. please explain ->(input)
do? , when use symbol ->
in ruby?
what ->(input) do?
->() { .. }
called staby proc.
and when use symbol -> in ruby?
when want use proc
object using kernel#lambda
method. ->() { .. }
syntactic sugar of kernel#lambda
.
ruby 1.9.1 introduces new, more concise syntax creating lambda methods.
the stab operator named resemblance knife or stabbing motion: ->
. following stab portion of operator, there argument list, in normal method. then, normal ruby block in braces.
since lambda's argument list formal argument list, opposed block argument list, several other features such default argument values supported. lambda somewhere in between anonymous block or closure , formal named method.
Comments
Post a Comment