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

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.

主站蜘蛛池模板: 张掖市| 长寿区| 昌图县| 郎溪县| 丰顺县| 淮安市| 宁强县| 遂川县| 宁波市| 循化| 阿克| 舟山市| 靖州| 黑河市| 张掖市| 慈溪市| 团风县| 平乡县| 乌海市| 鹤山市| 德钦县| 盖州市| 长葛市| 乐至县| 平山县| 孟津县| 扶绥县| 博客| 洮南市| 商都县| 珲春市| 新余市| 荥阳市| 繁昌县| 漳平市| 日照市| 托克托县| 灵石县| 邮箱| 金堂县| 东安县|