In the following example:
default: -> { Time.now } What's ->? I am familiar with => but first time I am seeing ->.
This answer is not useful. Show activity on this post. In Ruby Programming Language ("Methods, Procs, Lambdas, and Closures"), a lambda defined using -> is called lambda literal. succ = ->(x){ x+1 } succ.call(2) The code is equivalent to the following one.
In Ruby, a lambda is an object similar to a proc. Unlike a proc, a lambda requires a specific number of arguments passed to it, and it return s to its calling method rather than returning immediately. def proc_demo_method. proc_demo = Proc. new { return "Only I print!" }
It's the Ruby 1.9 "stabby lambda" operator. For example, see this article from 2008.
Nutshell:
> foo2 = ->(arg) { arg * 2 } > foo2.call "now" => nownow Note the lack of space between -> and (arg), that's intentional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With