- Comprehensive Ruby Programming
- Jordan Hudgens
- 111字
- 2021-07-02 21:13:31
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.
推薦閱讀
- 零基礎(chǔ)學(xué)C++程序設(shè)計
- CockroachDB權(quán)威指南
- ASP.NET動態(tài)網(wǎng)頁設(shè)計教程(第三版)
- Designing Hyper-V Solutions
- Oracle 18c 必須掌握的新特性:管理與實戰(zhàn)
- 深入理解Android:Wi-Fi、NFC和GPS卷
- Learning Concurrent Programming in Scala
- 深入淺出React和Redux
- 軟件測試實用教程
- SQL 經(jīng)典實例
- C#開發(fā)案例精粹
- Android開發(fā)三劍客:UML、模式與測試
- Python自然語言理解:自然語言理解系統(tǒng)開發(fā)與應(yīng)用實戰(zhàn)
- Instant GLEW
- 虛擬現(xiàn)實建模與編程(SketchUp+OSG開發(fā)技術(shù))