What is the -> (stab) operator in Ruby? [duplicate]

In the following example:

default: -> { Time.now }

What's ->? I am familiar with => but first time I am seeing ->.


Solution 1:

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.