When I am in irb or in rails and I create some iteration with each, I am getting the whole struct printed again in my terminal or inside the browser. Example:
a = [1,2,3,4]
a.each do |number|
puts n
end
The result in irb terminal or inside the browser:
1
2
3
4
=> [1,2,3,4]
Why does this => [1,2,3,4] appear inside the browser? I can’t create a single list in my page because the whole structure appears.
Every expression in Ruby returns a value; in
irb, the value returned by the expression you’ve just executed is displayed after=>.The return value of
Enumerable::eachis the object that calledeach– in this case, the array[1,2,3,4]