Ruby Extensions Project

Posted by MSch Mon, 21 Nov 2005 13:04:00 GMT

After reading about the Ruby Extensions Project in Why’s Hopping Through Pipes and Closures I decided to try it out.

I installed it via gem install -r extensions and started reading the documentation.

One of the many useful features I stumbled upon is the autoinit method: In the following example radius, location will be automagically assigned to the corresponding instance variables, while area will have some additional processing applied. And with the saved keystrokes I was able to type this post.
class Circle
  attr_reader :radius, :location, :area
  autoinit(:radius, :location) do
    @area = Math::PI * @radius ** 2
  end
end

Circle::new(1,2,3)

New with 0.6.0 comes require_relative, which requires a file relative to the file containing the statement.

Finally my_object.in? some_other_object provides a pythonesque way of expressing some_other_object.include?(my_object).

Of course there are many many more features but these are the ones that seem particularly useful to me

Tags  | no comments | no trackbacks

Older posts: 1 2