[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Adding a method to a single object

Marco Lange

1/9/2006 2:02:00 AM

Hi,

how is it possible to add a method to a single object programatically?
E.g. I want to write a method

class Object

def rename_method(old_id, new_id)
...
end

end

The method shall rename a method for a specific instance of any class,
e.g. the following should be possible:


a = 5
5.rename_method :times, :veces

5.times { ... }
-> Error, Method "times"does not exist

5.veces { ... }
-> Expected behaviour

I already succeeded in renaming methods for whole classes, but for a
single instance?

I do not really have a use case for such a method, but it is fun
learning about the object model in Ruby.

Best regards,
Marco
1 Answer

dblack

1/9/2006 2:20:00 AM

0