S
slothbear
I'm still learning Ruby, and most of the time I can find a beautiful
Ruby idiom that collapses two or more statements into one easy-to-read
(or learn) idiom, like h[key] ||= 0. My current project has a lot of
places where it emits lists if they contain any items, much like this:
unless items.empty?
puts "items\n-----"
items.each { |item| puts item }
end
My header code and list code is more complicated, and sometimes there
are lists within lists, and it all just starts to look ugly, even
split out into smaller methods. It would seem more Ruby-like if I
could fold the header into the iterator somehow -- rather than what I
have now that feels like it tests the Array for items twice. Or maybe
I'm trying too hard to make it terse?
Ruby idiom that collapses two or more statements into one easy-to-read
(or learn) idiom, like h[key] ||= 0. My current project has a lot of
places where it emits lists if they contain any items, much like this:
unless items.empty?
puts "items\n-----"
items.each { |item| puts item }
end
My header code and list code is more complicated, and sometimes there
are lists within lists, and it all just starts to look ugly, even
split out into smaller methods. It would seem more Ruby-like if I
could fold the header into the iterator somehow -- rather than what I
have now that feels like it tests the Array for items twice. Or maybe
I'm trying too hard to make it terse?