Robert Klemme
12/28/2005 1:42:00 PM
Jeff Cohen <cohen.jeff@gmail.com> wrote:
> unknown wrote:
>> You can directly define a method on a particular object:
>>
>> def obj.new_method
>> ...
>> end
>>
>
> That worked great! Thanks.
>
> Jeff
Just for the sake of completeness: if you are not allowed to modify the
original instance or do not want to do it there's a delegator module:
>> require 'delegate'
=> true
>> s="foo"
=> "foo"
>> o=SimpleDelegater.new s
=> "foo"
>> o.length
=> 3
>> def o.foo() length * 2 end
=> nil
>> o.foo
=> 6
>> o << "bar"
=> "foobar"
>> o.length
=> 6
>> o.foo
=> 12
Kind regards
robert