From: Mark Sparshatt Date: 2004-04-30T04:45:49+09:00 Subject: Re: coerce(), what protocol to implement it Jean-Hugues ROBERT wrote: > At 03:45 30/04/2004 +0900, you wrote: > >> 4) Can I redefine coerce() ? If so, when is it called ? (I tried, >> it is not called...) >> >> 5) By defining to_str() I can have "xx" + MyClass.new(xx) work. What >> do I have to redefine to have 1 + MyClass.new(xx) work ? >> this works for me class MyClass def initialize(val) @value = val end def coerce(other) [other, @value] end end 1 + MyClass.new(5) #=> 6 >> Google "ruby coerce" provided little help. >> You can find some information by searching the ruby-talk archives http://blade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml for coerce. HTH -- Mark Sparshatt