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:
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?
It does feel like it should be a separate method to me.
James Edward Gray II
···
On Nov 29, 2007, at 11:25 AM, slothbear wrote:
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:
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:
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?
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama
Thanks for the ideas. I ended up creating a separate method that
accepts a label and list as arguments. It looks pretty good and feels
pretty natural. Success! my thanks again.