Вот ответ, который делает то, что Вы ищете
def define_say(obj, msg)
# Get a handle to the singleton class of obj
metaclass = class << obj; self; end
# add the method using define_method instead of def x.say so we can use a closure
metaclass.send :define_method, :say do
puts msg
end
end
Использование (вставляют от IRB),
>> s = "my string"
=> "my string"
>> define_say(s, "I am S")
=> #<Proc:0xb6ed55b0@(irb):11>
>> s.say
I am S
=> nil
Для большего количества информации (и небольшой библиотеки, которая делает это менее грязным) читает это:
http://viewsourcecode.org/why/hacking/seeingMetaclassesClearly.html
Как в стороне, Если Вы - рубиновый программист, и Вы не считали, что, пойдите, делают это теперь ~!