From: Peter Zotov Date: 2011-08-02T15:25:35+09:00 Subject: Re: how to make 1+a work if a is not a numeric object? On Tue, 2 Aug 2011 15:15:10 +0900, Zd Yu wrote: > I defined a to_i method for a, but it seems not work. > > BTW, I do not want to override Fixnum's + method. Numeric#coerce is your friend: http://ruby-doc.org/core/classes/Numeric.html#M000959 For example: ruby-1.9.2 :001 > class A ruby-1.9.2 :002?> def coerce(other) ruby-1.9.2 :003?> [other, 5] ruby-1.9.2 :004?> end ruby-1.9.2 :005?> end => nil ruby-1.9.2 :006 > 1 + A.new => 6 -- WBR, Peter Zotov.