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

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.

主站蜘蛛池模板: 洪雅县| 韶关市| 万宁市| 东兴市| 罗平县| 洛隆县| 土默特右旗| 射洪县| 盈江县| 喜德县| 合江县| 蚌埠市| 高密市| 安乡县| 峨眉山市| 蓝田县| 屯门区| 汤原县| 昌吉市| 乌拉特中旗| 陆河县| 集贤县| 科尔| 华宁县| 青川县| 河北区| 永川市| 通化市| 岑溪市| 塔河县| 淅川县| 临澧县| 武宣县| 光泽县| 忻州市| 湘乡市| 兴山县| 曲水县| 南和县| 诸暨市| 苍山县|