The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Ruby and the Arch

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Jeremy Voorhis

Posts: 212
Nickname: jvoorhis
Registered: Oct, 2005

Jeremy Voorhis is a Rubyist in northeast Ohio.
Ruby and the Arch Posted: Mar 2, 2006 3:58 PM
Reply to this message Reply

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.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Jeremy Voorhis
Latest Posts From JVoorhis

Advertisement

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.

Read: Ruby and the Arch

Topic: Matching keywords in a string Previous Topic   Next Topic Topic: Extending script.aculo.us

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use