Christoph R.
11/6/2003 12:03:00 AM
dblack wrote:
...
> Of course the thing one probably wants to do is to modify classes and
> *not* break things :-) which is what singleton classes allow
> you to do. (See? Matz thought of it already :-) #extend is
> lovely, because it sandboxes things rather effectively and
> lets you do nice modular design. For example, I've got a
> program where I need a CGI object with extra capabilities.
> Originally I subclassed CGI, but that broke something (I
> think CGI must be particular about the return value of
> #class, or something -- I didn't dig deeply to find it). So
> now I've got a module with which I extend my CGI object, and
> I actually like that better. It's nice and clean, and keeps
> things tailored closely to the immediate needs of the objects.
H'm you are closet type-ist after all:-)
---
o = Object.new
module M
def first_mth
end
def second_mth
end
end
o.extend(M)
p o.is_a?(M) # true
---
/Christoph