From: Bob Hutchison Date: 2006-10-30T00:52:56+09:00 Subject: Re: Interesting trival example of why open classes are good? Hi, On 29-Oct-06, at 3:10 AM, Peter Michaux wrote: >> Examples abound where this open-class business comes in handy. > > 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. It isn't little, but xampl in Ruby makes heavy use of this capability (see my sig for links). I'd think that most code-generators could take advantage of open-classes. It also allows you to organise your source code, at least partially, on a functional basis rather than a class basis. It is also kind of central to the implementation of Ruby's definition of methods on objects, usually class objects, but not necessarily, allowing you to do stuff like: class Basics def initialize(name) @name = name end def tag return "#{@name} says" end def hello puts "#{tag}: hello" end def method_missing(s, *a, &b) puts "#{tag}: pardon?" end end a = Basics.new('a') b = Basics.new('b') a.hello b.hello a.bye b.bye def b.bye puts "#{tag}: bye" end a.bye b.bye Cheers, Bob > > Thanks again, > Peter > > ---- Bob Hutchison -- blogs at Recursive Design Inc. -- Raconteur -- xampl for Ruby --