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

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.

主站蜘蛛池模板: 永平县| 阿坝县| 琼结县| 郯城县| 和顺县| 绥德县| 松潘县| 靖宇县| 出国| 长葛市| 兴隆县| 大渡口区| 齐河县| 蓝田县| 桂林市| 开封县| 潞西市| 镶黄旗| 嘉祥县| 湟源县| 偏关县| 临海市| 南充市| 武安市| 南丰县| 绥德县| 乳源| 建德市| 庄浪县| 荃湾区| 渭南市| 璧山县| 乳山市| 华安县| 宁远县| 三门峡市| 柳江县| 沅江市| 兴安县| 宁波市| 论坛|