Archive for March, 2007

Ruby Docstrings

Friday, March 23rd, 2007

I can’t be the first person to come up with this, but since Google doesn’t show anything, I figured I’d share it.

Take the following code:

class Rect
  d"Calculates the area of the rectangle." do
    def area
      length * height
    end
  end

  d"The height of the rectangle." do
    attr_accessor :height
  end

  d"The length of the rectangle." do
    attr_accessor :length
  end
end

This lets us do:

irb(main):035:0> Rect.__doc__(:length)
=> "The length of the rectangle."
irb(main):036:0> Rect.__doc__(:area)
=> "Calculates the area of the rectangle."

Yay! Docstrings! So, how does this work?

(more…)

Ruby on Sarge…

Tuesday, March 6th, 2007

…is broken. Well, not really, but it does feel that way sometimes. Not only is the version of Ruby rather out of date (1.8.2), it’s split into separate packages so that you’re never sure if you’ve got everything you need, or if, when something’s not working, it’s because you just forgot to apt-get install something.

As an example, I was trying to get the wonderful Mechanize library working the other day. No matter what I tried, it just wouldn’t fly with the native Ruby – it complained about the Net::HTTP#use_ssl? method not being available. I couldn’t find any combination of packages that would do it. My usual port of call would be checkinstall, or possibly hacking the gem itself, but for one reason and another that wasn’t a viable option this time, and I didn’t have the time to get the editor out and get my hands dirty.

Enter Backports. I’d not had cause to use it before, but it really saved my bacon this time. Ruby 1.8.5 installed cleanly, Mechanise works, and the client and I are happy bunnies. Yay. Check there for instructions – it’s dead simple, and if you’re using a Sarge box, I reckon it’s too good not to know about.

Entries (RSS)