[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: simple loops and recursion

Gavin Kistner

11/27/2006 10:58:00 PM

From: ishamid [mailto:ishamid@colostate.edu]
> puts "Sorry, expected #{expected_value} but got #{actual_value}"
...
> The output does not distinguish number from numeral. Is this standard
> or is there something else going on?

The string representation (the output of the to_s method) for strings
and numbers is identical in this case. You might want to use the output
of the 'inspect' method instead, as this occasionally returns values
that are more in-line with what you want.

puts "Sorry, expected #{expected_value.inspect} but got
#{actual_value.inspect}"
===================
Sorry, expected "98" but got 98
===================

[ 1, '1', 1.275392, '1.275392', nil, /woot/ ].each do |obj|
puts "#{obj.to_s} vs #{obj.inspect}"
end

#=> 1 vs 1
#=> 1 vs "1"
#=> 1.275392 vs 1.275392
#=> 1.275392 vs "1.275392"
#=> vs nil
#=> (?-mix:woot) vs /woot/