From: mirian@... (Mirian Crzig Lennox) Date: 2001-05-28T09:38:47+09:00 Subject: [ruby-talk:15818] Re: is it possible to dynamically coerce objects types in Ruby? In article <991006658.571333.26080.nullmailer@ev.netlab.zetabits.com>, Yukihiro Matsumoto wrote: >If you reallly want MyClass to be integer that much, either > (a) define all numeric related operators/methods to MyClass. > (b) delegate every message to the (internal) integer. > (c) implement coerce mechanism by defining 'coerce' method (see p.354 > of the Pickaxe book). >Hope this helps. coerce is pretty nice, thank you. It seems that when I use coerce, I still have to define operators where MyClass is the left hand side of the expression; e.g., 4 + myObject # This is handled automatically by myObject's coerce but myObject + 4 # fails if myObject's class doesn't define '+'. Is this correct? --Mirian