[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:       Syver Enstad <syver-en+usenet () online ! no>
Date:       2002-09-19 18:01:31
[Download RAW message or body]

Paul Brannan <pbrannan@atdesk.com> writes:

> 
> 2) Correct me if I'm wrong, but I think python does let you add
> methods
> 
>    at run-time:

You're right, there are some objects you can't do it with though
strings and dictionaries come to mind.

You can do it smoother too. (I admit the ruby way is more explicit).

class Foo:
    pass

aFoo = Foo()

def aMethodToBecomeFoosSoon(self, arg):
    print self, arg


Foo.method = aMethodToBecomeFoosSoon

aFoo.method('aNiceString')




-- 

Vennlig hilsen 

Syver Enstad
[prev in list] [next in list] [prev in thread] [next in thread] 

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