官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 四会市| 景宁| 阿拉善盟| 呈贡县| 固镇县| 泾川县| 门源| 新化县| 昌都县| 武功县| 建昌县| 宁城县| 乌兰察布市| 安西县| 塘沽区| 陆良县| 天水市| 怀远县| 罗田县| 太白县| 新营市| 塔河县| 台北市| 南涧| 横山县| 乌鲁木齐市| 沈阳市| 民县| 察哈| 浏阳市| 乐安县| 东光县| 修文县| 信丰县| 林州市| 张家口市| 邹城市| 来凤县| 东阿县| 台安县| 大冶市|