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

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.

主站蜘蛛池模板: 石林| 黑水县| 阳朔县| 两当县| 镶黄旗| 来安县| 罗平县| 新竹县| 怀远县| 育儿| 红桥区| 维西| 增城市| 岳阳县| 江达县| 巴青县| 万山特区| 仁寿县| 枞阳县| 浪卡子县| 思南县| 勐海县| 武义县| 久治县| 田阳县| 喀喇| 阿图什市| 深水埗区| 河东区| 杭锦旗| 本溪市| 枣强县| 宁海县| 芜湖市| 阳信县| 隆安县| 黄石市| 平顶山市| 新密市| 井冈山市| 舟山市|