Hello, I need to add in runtime several methods to my class. How can I
accomplish this in ruby?
More precisely: I need my class to overload arithmetic operators with
fixnums in both ways (4+MyClass, MyClass+4). All the necessary info is
stored in a hash, so I created a method to do all the stuff. It looks
like do_operation(operator, other)
But still I have to add every single operator overloader:
class Fixnum
def doo_operation(operator, other)
#...nevermind...
end
def +(other)
do_operation(:+, other)
end
def -(other)
do_operation(:-, other)
end
end
can I automate it somehow?