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

The Ruby lambda tutorial

Similar to procs, lambdas allow you to store functions inside a variable and call the method from other parts of a program. In this lesson, we will discuss lambdas and show how to integrate them into a Ruby program.

To get started, I'll use the same example as the previous section, but with a different syntax.

full_name = lambda { |first, last| first + " " + last } 

You can also call lambdas in the same way as procs:

p full_name["jordan", "hudgens"] 

Notice that the implementation is nearly identical to using procs, with the only difference being the use of the lambda word instead of Proc.new.

主站蜘蛛池模板: 南投县| 乌审旗| 中方县| 湾仔区| 容城县| 岢岚县| 麻阳| 纳雍县| 增城市| 高唐县| 乌什县| 西吉县| 商河县| 石河子市| 华池县| 诸暨市| 桂阳县| 金湖县| 昆明市| 广平县| 吕梁市| 弥渡县| 台安县| 虞城县| 尖扎县| 鲁山县| 泸西县| 宁乡县| 彩票| 句容市| 济宁市| 隆子县| 两当县| 府谷县| 广平县| 乐陵市| 太保市| 个旧市| 马边| 航空| 蒙阴县|