Monday, September 3, 2007

require :gem_name

If you use Rails a lot you get very very used to using symbols as if they were keyword arguments. If you want to do this:

require :capistrano

instead of this:

require "capistrano"

it only requires a tiny change to gems. Go to line 27 of custom_require.rb (the path on a standard OS X box configured with port is /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb) and change this:

gem_original_require path

to this:

gem_original_require path.to_s

It's just syntactic sugar, but it feels more intuitive to me.

Update: I expanded this into a new version of the require method in custom_require.rb which also takes arrays.

Update again: damn it, this breaks sometimes. I don't know why.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.