Y
yuricake
I am not a total newbie in ruby, but I am still hazy on how things
like blocks, proc objects and contexts work under the covers. I have
experience with Lisp lambdas, so feel free to get technical.
My question is - why do the following two functions have different
behavior?
require "pp"
@@a = [1, 2, 3]
def q1
@@a.inject(0) {|sum, x|
pp x
return sum + x
}
end
def q2
@@a.inject(0) {|sum, x|
pp x
sum + x
}
end
like blocks, proc objects and contexts work under the covers. I have
experience with Lisp lambdas, so feel free to get technical.
My question is - why do the following two functions have different
behavior?
require "pp"
@@a = [1, 2, 3]
def q1
@@a.inject(0) {|sum, x|
pp x
return sum + x
}
end
def q2
@@a.inject(0) {|sum, x|
pp x
sum + x
}
end