If you execute your script on Ruby 1.9, you can use
Object#define_singleton_method to add a method to an object.
— begin: example —
class MyClass
end
MyClass.send(:define_method, :poof) {‘I say poof!’}
x = MyClass.new
y = MyClass.new
x.define_singleton_method( :poof_singleton ) { “Here is in a singleton
method.” }
x.poof_singleton #=> “Here is in a singleton method.”
y.poof_singleton #=> NoMethodError
— end: example —
The method Object#define_singleton_method is able to be used on Ruby
1.9, but I couldn’t find out its doc…