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

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.

主站蜘蛛池模板: 雷山县| 米易县| 读书| 宣恩县| 株洲县| 宁都县| 赤壁市| 五常市| 阿鲁科尔沁旗| 彝良县| 新龙县| 武城县| 卢龙县| 砚山县| 黄浦区| 霍林郭勒市| 香河县| 双流县| 永宁县| 新田县| 灵丘县| 琼结县| 阳朔县| 长治市| 宁德市| 喜德县| 政和县| 宁明县| 通河县| 佳木斯市| 金昌市| 乐东| 安徽省| 随州市| 长葛市| 揭西县| 通海县| 烟台市| 湘西| 专栏| 苏尼特右旗|