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

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.

主站蜘蛛池模板: 梅河口市| 西乌珠穆沁旗| 大安市| 利辛县| 肥东县| 筠连县| 南康市| 温泉县| 肇州县| 清远市| 昌平区| 佛山市| 迁安市| 丰都县| 双柏县| 德庆县| 沙河市| 阜康市| 贵德县| 南和县| 额尔古纳市| 英吉沙县| 奈曼旗| 昭通市| 靖边县| 遵义县| 潞城市| 东乌珠穆沁旗| 余干县| 平塘县| 洛川县| 平泉县| 金沙县| 东平县| 东阿县| 阳曲县| 沁水县| 华亭县| 道真| 兴文县| 吉木乃县|