⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 03 - blocks as closures - using outside variables within a code block.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
def add_to_all(array, number)  array.collect { |x| x + number }endadd_to_all([1, 2, 3], 10)                # => [11, 12, 13]#---tax_percent = 6position = lambda do  "I have always supported a #{tax_percent}% tax on imported limes."endposition.call# => "I have always supported a 6% tax on imported limes."tax_percent = 7.25position.call # => "I have always supported a 7.25% tax on imported limes."#---counter = 04.times { counter += 1; puts "Counter now #{counter}"}# Counter now 1# Counter now 2# Counter now 3# Counter now 4counter                                                  # => 4#---accumulator = [][1, 2, 3].reverse_each { |x| accumulator << x + 1 }accumulator                  # => [4, 3, 2]#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -