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

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.

主站蜘蛛池模板: 汉阴县| 天津市| 江津市| 青河县| 来安县| 临沧市| 刚察县| 沁源县| 伊春市| 台州市| 富锦市| 青州市| 双牌县| 陇川县| 克拉玛依市| 万州区| 屯留县| 同仁县| 梧州市| 舞钢市| 烟台市| 慈溪市| 柳河县| 敦化市| 漳平市| 缙云县| 探索| 祁连县| 安陆市| 永康市| 瑞丽市| 陆丰市| 武夷山市| 内丘县| 绵竹市| 赤壁市| 个旧市| 五原县| 社旗县| 德令哈市| 蓝山县|