This post originated from an RSS feed registered with Ruby Buzz
by Jeremy Voorhis.
Original Post: Ruby and the Arch
Feed Title: JVoorhis
Feed URL: http://feeds.feedburner.com/jvoorhis
Feed Description: JVoorhis is a Rubyist in northeast Ohio. He rambles about Ruby on Rails, development practices, other frameworks such as Django, and on other days he is just full of snark.
Often when I am faced with what seems a simple programming task but I am missing the requisite tools to make it happen, I think of Paul Graham’s notion of the arch and look for ways to build the language up to my application. A perfect and funny example of this is Enumerable#group_by. Just two days ago, I had written my own implementation of this iterator for a PLANET ARGON development project:
module Enumerable
def group_by
self.inject({}) do |h,v|
i = yield(v)
h[i] ||= []
h[i] << v
h
end.values
end
end
It is used like this:
american_cities.group_by { |c| c.state_code }
Oddly enough, today Jason Watkins pointed me to this Rails changeset
containing Marcel Molina’s implementation of group_by.
This coincidence, I think, confirms that programming from the bottom-up is both attainable and natural in Ruby language.