Hi --

On Sun, 29 Oct 2006, Peter Michaux wrote:

>>> 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?
>>
...
> Do you know of a nice little example that doesn't modify a built in
> Ruby class? I didn't realize I wasn't specific enough in my request.

That's harder, because if I give you an example like:

   class C
     def m
     end
   end

   class C
     def n
     end
   end

I might as well have written it in one definition block :-)

One possible use of this open-class feature is to put a class
definition in more than one file.  The Ruby library does this, for
example, with the Date class.  The pros and cons are probably pretty
self-explanatory.


David

-- 
                   David A. Black | dblack / wobblini.net
Author of "Ruby for Rails"   [1] | Ruby/Rails training & consultancy [3]
DABlog (DAB's Weblog)        [2] | Co-director, Ruby Central, Inc.   [4]
[1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com
[2] http://dablog.rubypal.com    | [4] http://www.rubycentral.org