On 10/29/06, dblack / wobblini.net <dblack / wobblini.net> wrote:
> 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.
>

A side-effect of this is that when working with a team, you are less
likely to need to merge changes in your SCM tool.
Imagine if every piece of ActiveRecord were in one file. Rails would
probably just be getting around to 'Hello, world' about now.