Or really, I know someone mentioned this, but..
puts "Your full name has #{full_length} characters."
Is the common ruby idiom ive seen.
sd
···
-----Original Message-----
From: Elliot Temple [mailto:curi@curi.us]
Sent: Friday, May 12, 2006 4:12 PM
To: ruby-talk@ruby-lang.org
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
This e-mail message may contain privileged and/or confidential information,
and is intended to be received only by persons entitled to receive such
information. If you have received this e-mail in error, please notify the
sender immediately. Please delete it and all attachments from any servers,
hard drives or any other media. Other use of this e-mail by you is strictly
prohibited.
All e-mails and attachments sent and received are subject to monitoring,
reading and archival by Seminis. The recipient of this e-mail is solely
responsible for checking for the presence of "Viruses" or other "Malware".
Seminis accepts no liability for any damage caused by any such code
transmitted by or accompanying this e-mail or any attachment.