Blocks and Methods
Proc Lambda
Proc and lambda objects store callable behavior in variables.
Proc Lambda
proc_lambda.rb
base =
doubler = Proc.new do |value|
value * 2
end
labeler = lambda do |value|
"value=#{value}"
end
result = doubler.call(base)
label = labeler.call(result)
puts "base=#{base}"
puts label
base =
doubler = Proc.new do |value|
value * 2
end
labeler = lambda do |value|
"value=#{value}"
end
result = doubler.call(base)
label = labeler.call(result)
puts "base=#{base}"
puts label
base =
doubler = Proc.new do |value|
value * 2
end
labeler = lambda do |value|
"value=#{value}"
end
result = doubler.call(base)
label = labeler.call(result)
puts "base=#{base}"
puts label
callable object
A callable object can be assigned to a variable and later invoked with `call`.