From: Max Norman Date: 2009-07-17T09:09:32+09:00 Subject: Re: Need Help with a Very, Very Simple Program David A. Black wrote: > Hi -- > > On Fri, 17 Jul 2009, Max Norman wrote: > >> I'm almost an absolute novice in Ruby; it is my first language and I >> just began learning the basics yesterday, using Chris Pine's 'Learning >> to Program.' > > Welcome to Ruby! > >> >> I'm receiving this error: String can't be coerced into Fixnum >> (TypeError).' Why can't this variable--which contains a numeric >> string--be converted into an integer? > > The reason is that better is an integer, but "That's better." is a > string. So it's like you're trying to do: > > 5 + "hello" > > and that doesn't work. You can convert back: > > puts better.to_s + "...That's better" > > or use Ruby's string interpolation syntax, which inserts expressions > into strings, via the #{} construct, and does the conversion for you: > > puts "#{better}...That's better." > > I've interpolated better, not better.to_s, and it will automatically > be to_s'd for me. > > > David > Welcome to Ruby! Thanks! I look forward to learning what appears to be an incredibly dynamic language. Ahh...I see. Thank you for that explanation. It's instances such as these that allow a few basic concepts to come together. -- Posted via http://www.ruby-forum.com/.