From: matz@... (Yukihiro Matsumoto) Date: 2001-05-28T08:53:04+09:00 Subject: [ruby-talk:15816] Re: is it possible to dynamically coerce objects types in Ruby? Hi, In message "[ruby-talk:15810] Re: is it possible to dynamically coerce objects types in Ruby?" on 01/05/28, Mirian Crzig Lennox writes: |This is great! However, I notice that when I try to use MyClass |objects in addition, I get these errors: | | m + 4 | ERR: (eval):1: undefined method `+' for # | | 4 + m | ERR: (eval):1:in `+': MyClass can't be coerced into Fixnum | |I'm not exactly sure what I need to do to make this work. 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. matz.