News for hackers. Stuff that matters.
Re:Pattern Matching in Ruby 2.7 (2019) by vidarh on Thursday January 09, 2020 @11:29AM (#22002543)
If each element of some_list responds to to_s with something sensible, which it would need to in order for puts to work in the first place, you can just write:

   puts some_list
This works as puts implicitly does the equivalent of calling Array() on its arguments and then calls `to_s` on each one.

`some_list.each ...` is somewhat more generic, as `puts some_list` requires `some_list` to respond to `to_ary` for it to work as expected, which is probably less common than implementing 'each'. (if you implement a collection class in Ruby, at least implement `each` and `to_ary`)

There are no comments on this comment yet.