Ruby-on-rails – Why is Ary.each to dump all content of the object?

foo is an array of objects, and bar is an attribute of the object.

(rdb:1) foo .bar.map{|v| bar.v }
["a", "b", "c", "d", "e", "f"]

< br />(rdb:1) foo.bar.each{|v| p bar.v }
[massive outpouring of object attributes]

Because the result of each is defined as an Enumerable object to be iterated.

If you want to use each in irb instead of overwhelming the output , Then:

foo.bar.each{|v| p bar.v }; nil

foo is An array of objects, bar is an attribute of the object.

(rdb:1) foo.bar.map{|v| bar.v }< br />["a", "b", "c", "d", "e", "f"]


(rdb:1) foo.bar.each {|v| p bar.v }
[massive outpouring of object attributes]

Because the result of each is defined as the Enumerable to be iterated Object.

If you want to use each in irb instead of flooding the output, then:

foo.bar.each{|v | p bar.v }; nil

Leave a Comment

Your email address will not be published.