Peter Michaux wrote:

> Hi,
> 
> I am trying to explain why the fact that Ruby's classes are never
> closed is advantageous. I can only think of relatively complex examples
> like Rails plugins. Does anyone have an interesting, standalone example
> showing the utility of open classes in under 30 lines? under 20?

That is way too easy.

---------------------------------

#!/usr/bin/ruby -w

class Fixnum
  def odd?
    return self & 1 == 1
  end
end

10.times do
  puts rand(30).odd?
end

---------------------------------

There is no "odd?" function in Fixnum, but adding one is trivial.

Examples abound where this open-class business comes in handy.

-- 
Paul Lutus
http://www.arachnoid.com