Comprehensive Ruby Programming
上QQ阅读APP看书,第一时间看更新

Stabby lambdas

In real-world projects, it's a common practice to use a different syntax though—the stabby lambda. Here is how you can use stabby lambdas:

full_name = -> (first, last) { first + " " + last } 

If you run this code, it runs exactly the same way as the previous one.

Like procs, you can also run the lambdas with the call syntax:

p first_name.call("jordan", "hudgens") 

So, that's how you create lambdas in Ruby with both the regular and stabby syntaxes.