From: Martin DeMello Date: 2006-11-28T06:55:34+09:00 Subject: Re: simple loops and recursion On 11/28/06, ishamid wrote: > puts "Sorry, expected #{expected_value} but got #{actual_value}" [...] > gives me > > =================== > Sorry, expected 98 but got 98 > =================== > > Of course, the problem is that I entered a string not an integer. > > The output does not distinguish number from numeral. Is this standard > or is there something else going on? When you interpolate an expression in a string, ruby first evaluates it, then calls to_s on the result. 98.to_s = "98" Here's an illustrative example - I'll define a class and give it a to_s method, then create an object of that class and embed it inside a string: irb(main):001:0> class MyClass irb(main):002:1> def to_s irb(main):003:2> "hello world" irb(main):004:2> end irb(main):005:1> end => nil irb(main):006:0> a = MyClass.new => hello world irb(main):007:0> puts "the language that cannot print '#{a}' is not the true language" the language that cannot print 'hello world' is not the true language => nil martin