Wednesday, January 04, 2006

RoR & Foos update

Tonight I decided to stop tinkering with the object/data model and start building the simplest ladder web app that would work. In pretty short order I was able to display a sports ladder (e.g., foosball) with names and positions. But a display-only ladder application isn't teribly useful so I figured the "easiest thing that works" was to allow a user to swap the positions of two teams on the ladder by selecting a couple checkboxes and clicking on a button labelled "swap positions".

After a couple hours work I had something that was minimally useful! :-) Then I decided that I really wanted to be able to support multiple ladders at the same time for both singles and doubles play (after all my overly-analyzed object model already supported it). And fortunately as I refactored the code I learned a bit more about Ruby on Rails' layouts and partials features. But one of the better ideas I had was adding a signup method to my ladder class that looks like this:

def signup( players, screen_name = 'undefined' )
[...]
end


It can be used like this:

singles_ladder.signup([joe])
doubles_ladder.signup([bob, doug], 'Hosers')


Certainly a lot simpler than the code I had before that created a team, added the players to the team and then added the team to the ladder. For some reason it just felt more Ruby-like to do it this way.

No comments: