S
Spitfire
I've read that in Ruby the value returned from a code block is the
value of the last expression executed. Is it so? If Yes, I don't
understand the value returned by the following code block!
def clistIter
clist = [1, 2, 3]
clist.each do |elem|
yield(elem)
end
end
clistIter { |e| print e }
## output in irb:
## 123 => [1, 2, 3]
##
## returned value:
## => [1, 2, 3]
Can someone explain how come an array is returned as result?
value of the last expression executed. Is it so? If Yes, I don't
understand the value returned by the following code block!
def clistIter
clist = [1, 2, 3]
clist.each do |elem|
yield(elem)
end
end
clistIter { |e| print e }
## output in irb:
## 123 => [1, 2, 3]
##
## returned value:
## => [1, 2, 3]
Can someone explain how come an array is returned as result?