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

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.

主站蜘蛛池模板: 台州市| 碌曲县| 西盟| 饶阳县| 揭西县| 孝感市| 金平| 法库县| 博白县| 扶风县| 罗山县| 和政县| 榆社县| 宿州市| 崇阳县| 福鼎市| 敦化市| 南乐县| 龙泉市| 广安市| 梁平县| 莲花县| 探索| 临潭县| 沅陵县| 晋中市| 山阳县| 咸宁市| 武乡县| 日喀则市| 修文县| 开封市| 牟定县| 阳原县| 黄大仙区| 布拖县| 仙居县| 罗平县| 徐汇区| 遂宁市| 三江|