From: Morton Goldberg Date: 2006-07-30T02:30:29+09:00 Subject: Re: to_i vs. to_int On Jul 29, 2006, at 12:58 PM, dblack@wobblini.net wrote: > What's a use case for to_int? I was thinking of this classic to_str > example: > > class S > def to_str > "some text" > end > end > > puts "Here is " + S.new # Here is some text > > But the to_int equivalent doesn't work: > > class S > def to_int > 2 > end > end > > puts 2 + S.new # TypeError: S can't be coerced into Fixnum > > Same thing with: > > puts Integer(2) + S.new > > I'm stuck trying to find a case where to_int does what to_str does -- > but maybe it doesn't. However, puts 2 + Integer(S.new) => 4 uses your S#to_int Regards, Morton