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

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.

主站蜘蛛池模板: 印江| 上杭县| 桑日县| 南丰县| 仙游县| 白银市| 攀枝花市| 宜宾县| 抚顺市| 富源县| 阿拉善左旗| 沛县| 济源市| 上栗县| 福贡县| 南丹县| 台湾省| 多伦县| 专栏| 当涂县| 抚顺市| 泗水县| 遵义市| 南靖县| 宜宾县| 朔州市| 道真| 永清县| 思茅市| 洱源县| 名山县| 利川市| 万安县| 固阳县| 宣武区| 疏附县| 湖北省| 秭归县| 荃湾区| 汉寿县| 凤山市|