- 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.
推薦閱讀
- Designing Machine Learning Systems with Python
- Computer Vision for the Web
- UML+OOPC嵌入式C語(yǔ)言開發(fā)精講
- 深入淺出Android Jetpack
- PLC編程及應(yīng)用實(shí)戰(zhàn)
- PhoneGap Mobile Application Development Cookbook
- Node.js Design Patterns
- C語(yǔ)言程序設(shè)計(jì)
- Working with Odoo
- Frank Kane's Taming Big Data with Apache Spark and Python
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)教程(Windows 7+Office 2010)
- Unity Character Animation with Mecanim
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)項(xiàng)目化教程
- Functional Python Programming
- 城市信息模型平臺(tái)頂層設(shè)計(jì)與實(shí)踐