jonas <jonas.bulow / servicefactory.se> writes: > > Try 'to_int' which is for that particular purpose, not 'to_i' which is > > for explicit conversion to integer. And when you want something to be > > string, try 'to_str'. > > Why is there a difference between to_i and to_int? Is it the principle > of biggest surprise!? :-) The longer forms to to_xxx (to_int, to_str, and to_ary) are used when the argument is _expected_ to be of a particular type. to_i, to_a, and to_s and used to _convert_ something to that type. There's a big difference: to can convert just about anything to a string, but it's not always meaningful to use that value where a string is expected: f = File.new("/dev/null") f.to_s #=>"#<File:0x4018da54>" f =~ /wombat/ #=> failed to convert File to String