New in Rails: Enumerable#group_by and Array#in_groups_of

Changeset 3726 adds two little methods to ActiveSupport: Enumerable#group_by and @ Array#in_groups_of@.

Enumerable#group_by is for collecting an enumerable into sets, grouped by the result of a block. Useful, for example, for grouping records by date.

     latest_transcripts.group_by(&:day).each do |day, transcripts| 
       p "#{day} -> #{ * ', '}"
     "2006-03-01 -> Transcript"
     "2006-02-28 -> Transcript"
     "2006-02-27 -> Transcript, Transcript"
     "2006-02-26 -> Transcript, Transcript"

Enumerable#group_by will be baked right into Ruby in the future, and currently lives in the 1.9 branch.

Array#in_groups_of let’s you iterate over an array in groups of a certain size, optionally padding any remaining
slots with a specified value (nil by default).

     %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g}
     ["1", "2", "3"]
     ["4", "5", "6"]
     ["7", nil, nil]

You gotta love the elegant encapsulation afforded by blocks! Yield.

Two Ruby articles in the latest ObjectiveView

ObjectiveView, a journal for software developers that focuses each issue on a specific topic, has two Ruby related articles in their latest issue, New Technologies Focus.

The first is an introduction to Ruby by Amy Hoy. She brings her quirky right-brained ebullience to bear, providing a thorough yet accessible tour of Ruby. She emphasizes that one of its most salient characteristics is that it makes you happy. If her writing style is any indication, she’s loving life.

ThoughtWorker Obie Fernandez serves up the other article which demonstrats what DHH’s often cited phrase “opinionated software” means and how it relates to Rails. Keep an eye out for Obie’s upcoming book, Extending Ruby on Rails (Into the Enterprise) which is expected out in Fall 2006 by Addison-Wesley.

These two tutorials provide a nice introduction to both Ruby and Rails.

Past issues of ObjectView which focus on such topics as agile development, use cases and componentized development, are also available, so check out the rest of the back issues on their website.

New for Rails 1.1: Integration Tests

If you’ve ever tried to properly test complex scenarios involving multiple controller actions, you will notice that the Rails Functional Tests fall flat. The new Integration Tests, which have just been introduced into the Rails trunk, will solve that. From the documentation:

An IntegrationTest is one that spans multiple controllers and actions, tying them all together to ensure they work together as expected. It tests more completely than either unit or functional tests do, exercising the entire stack, from the dispatcher to the database.

The provided example also shows a glimpse into the testing DSL that is used in Campfire:

class AdvancedTest < ActionController::IntegrationTest
  fixtures :people, :rooms

  def test_login_and_speak
    jamis, david = login(:jamis), login(:david)
    room = rooms(:office)

    jamis.speak(room, "anybody home?")

    david.speak(room, "hello!")

Integration Tests will be included with Rails 1.1. Get ready!

Jim Weirich on the Rails podcast

Jim Weirich has been using Ruby for ages. He’s one of the early-adopter all-stars from the days before Rails. Rails programmers will be familiar with his wildly popular and influencial Rake and Builder projects. He’s also one of the main developers of RubyGems, which is scheduled to be included with Ruby in an upcoming release.

The enthusiasm he brings to his work and talking about his work make it clear that he has a genuine love for programming. On top of it all, cliches aside, he’s one of the nicest people you’ll ever meet.

So what a treat to have him on the
Ruby on Rails podcast. Have a listen.

Cheers to Geoffrey Grosenbach for snagging yet another great guest.

Using Ruby on Rails on Mac OS X at the Apple Developer Connection

The Apple Developer Connection has a nice Ruby on Rails tutorial called Using Ruby on Rails for Web Development on Mac OS X. As the title suggests, it is aimed at getting OS X users off the ground with Rails.

The Apple Developer Connection doesn’t supply any attribution for their articles, but this one was written by none other than Mike Clark, who along with Dave Thomas runs the always-sold-out Pragmatic Studio series of Ruby on Rails and Ajax training.

Cheers to Mike for taking the time out of his busy schedule to write up a great tutorial.

Rails is Boring and Ruby is a Toy

CUSEC 2006 in Montreal this past January featured a great line up of speakers including Chad Fowler, Kathy Sierra and David Heinemeier Hansson.

Except snow storms in the midwest kept David from making it, so with 12 hours of advanced notice, Rails Recipes author Chad Fowler flexed his jazz improv background by whipping up an entertaining, wise and cool-as-cucumber talk in place of David’s keynote. The result is Rails is Boring and Ruby is a Toy.

Thanks to SOENlive for making the talk available. You can get the rest of the conference by subscribing to the SOENlive podcast on iTunes.

List of what's coming up in Rails 1.1

Today someone on the Rails mailing list asked, innocently enough, “Is there by any chance some document available summarizing all the
(major) beautiful new stuff in Rails 1.1?” As is to be expected, he received instructions on how to do a diff between the 1.0 release tag and trunk as well as links to the CHANGELOGS. He used “summarize” carefully. Turns out there was nothing like he was looking for. Well, not for long…

Scott Raymond, of Blinksale and IconBuffet fame, rolled up his sleeves and did the dirty work for the rest of us. So, as requested, here is a summary of what will be new in Rails 1.1. Thanks Scott.

Campfire: Web-based chatting on Rails

Campfire by 37signals has launched. It’s web-based group chat for business where file transfers work reliably and where you have shared access to the logs.

It’s also dripping with delicious Ajax, courtesy of Prototype maestro Sam Stephenson, who joined 37signals in December along with Marcel Molina. So go check it out. More details about the launch on Loud Thinking and 37signals.

RailsConf: 150 additional seats <strike>open</strike> GONE!

Due to the overwhelming success of selling 400 seats in just a week, RailsConf has been able to extend the venue and open up an additional 150 seats. So if you missed out during the first round of registrations, now would be a very good time to expedite that intention to be there and sign up. Hope to see you in Chicago in June!

UPDATE: Away they went! The additional 150 seats have been sold in a little less than 24 hours and we’re thus full. We’re going to have one hell of a time with 550 Railers in the room. Awesome!

Two new interviews with Rails creator David Heinemeier Hansson

MySQL developer Lenz Grimmer has a quick chat with David for the MySQL developer zone.

Also, has a long and insightful interview. David explains how 1.0 should have really been 2.0, what the continuum of database evil entails, why Rails is useful for the enterprise and the joys of aesthetic moments with Ruby. It’s a laundry list of David’s ideology, all in one place. A window into the culture and personality driving Rails.

Choice excerpts:

  • I am not a vendor. I don’t work on Rails to please other people, I work on it to please me. That’s the beauty of open source. I’m free to make technology choices unrestricted by legacy or ill-advised customers. If you don’t “buy” Rails, it’s no skin off my back. There are plenty of people who do buy it because they share the priorities presented.
  • So if labelling me “crazy” helps you ignore the disruptions Rails is bringing to the table, I say go for it. Maybe that’s an accurate label for me in the current situation you’re in. And if there’s no interest or ability to get out of that situation, it’s probably best to write me and Rails off as crazy such that you can head into work with a smile tomorrow.
  • Once a high-level component becomes big enough to be interesting, it’ll take more work to configure it than it would take to build just what you needed from scratch.

Should be required reading for anyone interested in Rails.