From: Elliot Temple Date: 2006-05-13T08:11:57+09:00 Subject: Re: conversion issues you're trying to add a string and an integer. it's like writing: 3 + " dogs" you should write 3.to_s + " dogs" On May 12, 2006, at 4:05 PM, corey konrad wrote: > >> It printed out "5" just fine. Is that the problem you were >> referring to? >> > > actually this one, i have to use + full_name.to_s + to avoid the > error i > just found that strange. i mean i am using a string method the to_s > should be implicit shouldnt it? i dont know. > > irb(main):030:0> def name_length > irb(main):031:1> p "what is your first name?" > irb(main):032:1> first = gets.chomp > irb(main):033:1> p "what is your last name?" > irb(main):034:1> last = gets.chomp > irb(main):035:1> full_length = first.length + last.length > irb(main):036:1> p "your full name has: " + full_length + > "characters" > irb(main):037:1> end > => nil > irb(main):038:0> name_length > "what is your first name?" > corey > "what is your last name?" > konrad > TypeError: can't convert Fixnum into String > from (irb):36:in `+' > from (irb):36:in `name_length' > from (irb):38 > from :0 > > > -- > Posted via http://www.ruby-forum.com/. > > -- Elliot Temple http://www.curi.us/blog/