module Age

Public Instance Methods

kid_birthday(name) click to toggle source
# File lib/quotejar/age.rb, line 8
def kid_birthday(name)
  puts "What is #{name}'s birthday?"
  puts "Enter the year:" 
  prompt 
  year = gets.chomp
  puts "Enter the month as a two digit number:"
  prompt
  month = gets.chomp
  puts "Enter the day as a two digit number:"
  prompt
  day = gets.chomp 
  Time.new(year, month, day)
end
prompt() click to toggle source
# File lib/quotejar/age.rb, line 4
def prompt
  print ">> "
end
quote_age(date, birth_date) click to toggle source
# File lib/quotejar/age.rb, line 42
def quote_age(date, birth_date)
  (date - birth_date) / 31557600 # divided by seconds in a year to get age
end
quote_date() click to toggle source
# File lib/quotejar/age.rb, line 22
def quote_date
  puts "What's the date? If you want to enter a day, enter 'Y'. Enter 'N' for today's date."
  prompt
  answer = gets.chomp.downcase
  if answer == 'y'
    puts "Enter the year:" 
    prompt
    year = gets.chomp
    puts "Enter the month as a two digit number:"
    prompt
    month = gets.chomp
    puts "Enter the day as a two digit number:"
    prompt
    day = gets.chomp 
    Time.new(year, month, day)
  else
    Time.new
  end
end