tsykの日記: A genic program counter nobody can avoid. 2
日記 by
tsyk
#!ruby
require 'date'
class Human
attr_reader :date_of_birth
def initialize(year, month, mday)
@date_of_birth = Date.new(year, month, mday)
end
def age
today = Date.today
y = today.year - @date_of_birth.year
m = today.month - @date_of_birth.month
d = today.mday - @date_of_birth.mday
y -= 1 unless m >= 0 and d >= 0
y
end
def birthday?
today = Date.today
today.month == @date_of_birth.month and
today.mday == @date_of_birth.mday
end
end
tsyk = Human.new(19XX, 11, 26)
puts tsyk.date_of_birth
puts tsyk.age
puts "Happy Birthday!" if tsyk.birthday?
require 'date'
class Human
attr_reader :date_of_birth
def initialize(year, month, mday)
@date_of_birth = Date.new(year, month, mday)
end
def age
today = Date.today
y = today.year - @date_of_birth.year
m = today.month - @date_of_birth.month
d = today.mday - @date_of_birth.mday
y -= 1 unless m >= 0 and d >= 0
y
end
def birthday?
today = Date.today
today.month == @date_of_birth.month and
today.mday == @date_of_birth.mday
end
end
tsyk = Human.new(19XX, 11, 26)
puts tsyk.date_of_birth
puts tsyk.age
puts "Happy Birthday!" if tsyk.birthday?
なんのひねりもなく... (スコア:1)
(define (main args)
(display "おめでとうございます!!!")
(newline))
-- cooper
ありがとうございます (スコア:1)