- 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.
推薦閱讀
- Web程序設計及應用
- Mastering Adobe Captivate 2017(Fourth Edition)
- Architecting the Industrial Internet
- Python高級機器學習
- 區(qū)塊鏈:以太坊DApp開發(fā)實戰(zhàn)
- STM32F0實戰(zhàn):基于HAL庫開發(fā)
- Python完全自學教程
- R Data Analysis Cookbook(Second Edition)
- Protocol-Oriented Programming with Swift
- SQL基礎教程(第2版)
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發(fā)視頻大講堂)
- Java Web從入門到精通(第3版)
- Java編程從入門到精通
- 零代碼實戰(zhàn):企業(yè)級應用搭建與案例詳解
- 基于GPU加速的計算機視覺編程:使用OpenCV和CUDA實時處理復雜圖像數據