Topic: Noob help: puts

so i have a situation where ruby gets multiple characteristics of a character. when i put the variables, there are unnecessary line breaks. here's my code...

#Beginning game file

#Welcome to my game. I==N00b

class Character
    attr_accessor(:name, :age, :gender, :birthplace)

print ("What's your character's name? ")

print ("How old is your character? ")

print ("Are you a boy or a girl? ")

print ("Where is your character from? ")

puts("#{} is a #{c1.age.to_i} year old #{c1.gender.to_s} hero from #{c1.birthplace.to_s}.")

This returns the following,

What's your character's name? Joe
How old is your character? 7
Are you a boy or a girl? Boy
Where is your character from? swaziland

is a 7 year old Boy
hero from swaziland

How do I the text to be on one line like this.

Joe is a 7 year old Boy hero from swaziland.

The problem is probably when the user presses the enter button, the enter acts as a new line.

How can I fix this?


Last edited by joemama (2012-06-05 21:43:50)

Re: Noob help: puts

Just use String#chomp method on every input string, for example:

print ("What's your character's name? ")

#do the same for the others attributes