In Ruby, why is a method invocation not be able to be treated as a unit when "do" and "end" is used?
- by Jian Lin
The following question is related to the question "Ruby Print Inject Do Syntax". My question is, can we insist on using do and end and make it work with puts or p?
This works:
a = [1,2,3,4]
b = a.inject do |sum, x|
sum + x
end
puts b # prints out 10
so, is it correct to say, inject is a class method of the Array class, which takes a block…