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

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.

主站蜘蛛池模板: 自治县| 长沙市| 松原市| 措勤县| 安西县| 汨罗市| 茶陵县| 房山区| 临洮县| 清流县| 贺州市| 都昌县| 凤冈县| 涿州市| 鹤峰县| 潮州市| 滦南县| 五华县| 汪清县| 墨玉县| 义乌市| 磴口县| 垫江县| 滨海县| 双柏县| 东乌珠穆沁旗| 兰州市| 荆门市| 高青县| 会昌县| 满洲里市| 陆良县| 西乌珠穆沁旗| 临湘市| 乐都县| 邹城市| 本溪| 高安市| 荣成市| 乾安县| 湖口县|