Hi --
On Thu, 28 Dec 2006, Ja Bo wrote:
> I am brand new to Ruby and I would greatly appreciate any help you guys
> can provide!
>
> If this is not the correct place to post them please let me know where I
> should post these types of questions.
>
> This very short program is just supposed to take today's date using t =
> Time.now and calculating what year the user was born...
>
> Code:
> puts "How old are you?"
> age = gets.chomp
>
> puts name + " is " + age + " years old."
>
> t = Time.now
> born = t.year - age
The problem there is that t.year is an integer and age is a string.
You need to convert age:
born = t.year - age.to_i # to_i is "to integer"
> puts "You were probably born in " + born + "."
And don't forget you can use string interpolation:
puts "You were probably born in #{born}."
Or even do it all at once:
puts "You were probably born in #{Time.now.year - age.to_i}."
David
--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (
http://www.manning.com/black)
(See what readers are saying!
http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (
http://www.rubypal.com)