There was a time when I was pioneering the mysterious genre of initialize method Moe alone, but I am often asked by students about the differences between classes and instances, instance methods and class method classifications and roles, so I will link to the above link again. I'm going to code what I mention in the article.
[The story that the initialization is cute] → https://qiita.com/yamazaki_akihiro/private/32ea4cf5e653913d2485
class Mother
def initialize(sleeper)
puts "#{sleeper}I entered my room, but there is no sign of waking up. It ’s a really calm sleep."
@sleeper = sleeper
end
def ding_frypan
puts ""Yeah !!!!" * The frying pan is ringing. It's a nuisance to the neighborhood"
puts ""Gwahhhh !!!"#{@sleeper}The death devil!"
end
def open_curtain
puts ""Yeah !!!!" * The curtains were opened vigorously. Not recommended as it puts a load on the rails"
puts ""Gwahhhh !!!"#{@sleeper}The death devil!"
end
def strip_duvet
puts ""Yeah !!!!" * I removed the futon. If this is a romantic comedy, there will be various things after this and the two will be late, but this time it is different"
puts ""Gwahhhh !!!"#{@sleeper}The death devil!"
end
def self.go_job
puts ""I don't know my mom even if I'm late!""
puts "And my mother disappeared into the city surrounded by the morning mist..."
end
end
puts "It's 7 o'clock. Would you like to wake up oversleeping soon?"
puts "1,Go to the room and wake up"
puts "2,Go to work without waking up"
num = gets.to_i
if num == 1
puts "Who do you wake up?"
sleeper = gets.chomp
mother = Mother.new(sleeper)
puts "How do you wake it up?"
puts "1,Ring the frying pan(It's noisy!)"
puts "2,Open the curtains and let the morning sun shine(It's dazzling!)"
puts "3,Remove the futon(It's cold! * It may be a little embarrassing when you are adolescent)"
plan = gets.to_i
if plan == 1
mother.ding_frypan
elsif plan == 2
mother.open_curtain
elsif plan == 3
mother.strip_duvet
else
puts "You don't really want to wake it up. Let's work"
Mother.go_job
end
elsif num == 2
Mother.go_job
else
puts "You guys! Well, I'm not a mother! !! !! What guy! !! ??"
end
Recommended Posts