我在解决实际问题的时候,遇到了关于 lambda 的问题,不清楚 Ruby 中的 lambda 是否能像下面这样用。
lambda_x = ->(x) {
if x == 0
return
else
puts "Some Operaions..."
lambda_x[ x-1 ]
end
}
lambda_x[10]
lambda_x = ->(x) {
puts "Some Operations..."
}
base = 10
lambda_y = ->(another_lambda) {
if base == 0
return
else
puts 'Some Operations...'
another_lambda[ base**2 ]
base -= 1
lambda_y[ another_lambda ]
end
}
lambda_y[ lambda_x ]
lambda_x = ->(x) {
puts "Some Operations..."
}
base = 10
lambda_y = ->{
if base == 0
return
else
puts 'Some Operations...'
lambda_x[ base**2 ]
base -= 1
lambda_y.call
end
}
lambda_y.call
可以像上面这样用吗?