[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Is better to subclass or to add methods to an existing class?
From:       Dossy <dossy () panoptic ! com>
Date:       2002-09-19 12:55:31
[Download RAW message or body]

On 2002.09.19, Vincent Foley <vinfoley@iquebec.com> wrote:
> 
> But my friend told me that Python didn't have that because it was not a
> good thing and it was not the proper way to do it.  He said that the
> true way of doing it, is to subclass (since Python 2.2 can now subclass
> builtin types) the base class:

Um, what is Python doing with this block of code:

def foo():
    print "foo"

??  In Ruby, it simply adds a private method to the current object.

So, if Python does the same (allowing you to add methods to instances
of objects at runtime) then why would being able to add methods to a
class of objects at runtime be the wrong thing?

Granted I think in Ruby the inclination to add methods to existing base
classes instead of subclassing them may be more common than it should
be, but the feature is certainly one that makes Ruby very powerful when
done right.

-- Dossy

-- 
Dossy Shiobara                       mail: dossy@panoptic.com 
Panoptic Computer Network             web: http://www.panoptic.com/ 
  "He realized the fastest way to change is to laugh at your own
    folly -- then you can let go and quickly move on." (p. 70)
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic