Add method to an instance : singleton_method_added « Reflection « Ruby






Add method to an instance

a = "hello" 

b = a.dup 
def a.to_s 
    "The value is '#{self}'" 
end 

def a.twoTimes 
    self + self 
end 

a.to_s 
a.twoTimes
b.to_s 

 








Related examples in the same category

1.Use singleton_method_added to call a singleton method
2."class <