Archive for the ‘ruby and rails’ Category

Happy Anniversary to me!

Sunday, January 11th, 2009

I was just on Working with Rails the other day, and I noticed that my profile says I’ve been using Ruby and Rails for 4 years now. After thinking a bit, I’ve realized that that’s correct—I watched the development of Rails through the end of 2004, but I really only started experimenting with it at the beginning of 2005 (version 0.10ish), and I launched my first application* with it in late January of 2005. It took a while longer before I was able to use Ruby and Rails full-time, but the start of it all was darn close to exactly four years ago. Wow!

Since then, I’ve spoken in the US, Italy, and Germany, written a book, and met some amazing people—but the biggest benefit has been working in a language and with a framework that I really enjoy. So, thanks to Matz and the Ruby team, DHH and the Rails team, and to everyone else who’s contributed to either over the years. Here’s to the future!

* It was a simple GTD/todo list application, if you must ask.

Method Visibility and Modules

Friday, January 2nd, 2009

I was doing some debugging on a Rails application the other day, and I noticed the following in script/console:

>> (MonkeysController.new.methods - ActionController::Base.new.methods).sort
=> ["check_for_buildout", "filter_parameters", "index", "inform_hoptoad",
    "notify_hoptoad", "rescue_action_in_public_with_hoptoad",
    "rescue_action_in_public_without_hoptoad"]

My MonkeysController (name changed to protect the innocent) has only one action, index—but it’s got all these other things publicly available. Clearly, several of them are coming from the Hoptoad plugin, and one (check_for_buildout) is from my own IntegratedBuildouts plugin… I’m less concerned about where these methods came from, however, than I am about why they show up in the public interface of my controller. Ideally, the only methods a controller should advertise are its actions; anything else is subject to abuse (especially if you’ve left the heinous default route in your app).

Obviously, these methods are being added by the inclusion of some modules (include HoptoadNotifier::Catcher, for instance), so I thought a bit and realized that I’ve never really looked for a way to add visibility-limited methods (protected and private) to a class from a module.

So I tried the following:

module Primate
  def m1; end

  protected
  def m2; end

  private
  def m3; end
end

class Monkey
  include Primate

  def c1; end

  protected
  def c2; end

  private
  def c3; end
end

Lo and behold, it works!

(Monkey.new.public_methods - Object.new.public_methods).sort        # [c1, m1]
(Monkey.new.protected_methods - Object.new.protected_methods).sort  # [c2, m2]
(Monkey.new.private_methods - Object.new.private_methods).sort      # [c3, m3]

So, for all you plugin and library writers out there—add the correct visibility markers to your modules! It’s so easy (and obvious) that there’s no excuse not to.

2008 Rails Rumble, Done

Sunday, November 9th, 2008

Rails Rumble 2008

Ack! In the process of writing that quick post on my Rubyconf presentation, I noticed that I’ve completely neglected talking about the Rails Rumble. As it turns out, I kind of won the solo divisionagain.

I love the Rumble; it’s one of the most inspiring competitions I’ve ever been a part of (including the create-your-own-He-Man-character one that I did when I was ten or so, which ’til the Rumble came along had been the high point for me :). There’s just something about sitting down to an empty project on Friday night, hacking away for 2 straight days, and deploying something useful (or cool or whatever) at the end. This year in particular I’m gratified that people liked my entry, Forever Home, because it represents a cause close to my heart (dogs needing adoption). I’m also amazed that I pulled out the win over the course of the last day, since the other solo entries were extraordinary.

Oh, and there’s a rumor in the air that there could be more frequent Rumbles in the future—that’d be an exciting thing. Why limit the fun to just once a year?

And… Session Aftermath

Thursday, September 4th, 2008

My second session at Railsconf Europe ended a few hours ago, and marks the third time I’ve talked about Advanced RESTful Rails. This one went noticeably better than the tutorial (I’m thinking <1 hour is my timeframe of choice, going forward), and I got some great suggestions and questions at the end.

I’ll have slides up on SlideShare as soon as I can, but I’m still having issues sending largeish files over the internet here (either wireless or wired)—keep an eye on this post for the eventual update.

And here they are:

At this point, I’m kind of sad to retire this talk… I think people get a lot out of it, and every time I give it I learn something new.

Tutorial Aftermath

Wednesday, September 3rd, 2008

So, yesterday morning (0830 CET, 0230 EST) was my tutorial on resourceful plugins at Railsconf Europe. Other than flying through the material and running short, it went pretty well. We ended up writing a fair chunk of code semi-collaboritively, so I’ve uploaded that to GitHub (I’ve also updated it a bit since the tutorial).

Here are the slides, though they probably won’t be all that helpful.

Resourceful Plugins
View SlideShare presentation or Upload your own. (tags: railsconfeurope2008)

Also, as a result of the work we did in the tutorial, I spent a few hours today working up an initial version of a resourceful forum plugin. There’ll be a more official announcement sometime next week on Viget Extend, but if you’re interested in a preview take a look at this.