[RUBY] About the role of the initialize method

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

  def ding_frypan
    puts ""Yeah !!!!" * The frying pan is ringing. It's a nuisance to the neighborhood"
    puts ""Gwahhhh !!!"#{@sleeper}The death devil!"

  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!"

  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!"

  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..."

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
  elsif plan == 2
  elsif plan == 3
    puts "You don't really want to wake it up. Let's work"
elsif num == 2
  puts "You guys! Well, I'm not a mother! !! !! What guy! !! ??"

Recommended Posts

About the role of the initialize method
About the method
Output about the method # 2
About the length method
About the authenticate method.
About the map method
About the ancestors method
About the to_s method.
Output about the method Part 1
about the where method (rails)
About the description of Docker-compose.yml
Consideration about the times method
What is the initialize method?
About the behavior of ruby Hash # ==
About the basics of Android development
[Ruby] Questions and verification about the number of method arguments
initialize method
Think about the 7 rules of Optional
Summary about the introduction of Device
About the log level of java.util.logging.Logger
What is testing? ・ About the importance of testing
About the operation of next () and nextLine ()
About the initial display of Spring Framework
About the error message Invalid redeclaration of'***'
About the treatment of BigDecimal (with reflection)
Deepened my understanding of the merge method
About the number of threads of Completable Future
About the mechanism of the Web and HTTP
[Ruby basics] About the role of true and break in the while statement
About the continuous division method learned in the 4th grade of elementary school
[Ruby] initialize method
About the package
[Order method] Set the order of data in Rails
[Java] Handling of JavaBeans in the method chain
About the official start guide of Spring Framework
About the description order of Java system properties
About the idea of anonymous classes in Java
The order of Java method modifiers is fixed
Output of how to use the slice method
About call timing and arguments of addToBackStack method
About next () and nextLine () of the Scanner class
ArrayList and the role of the interface seen from List
About No Method Error
Ruby Learning # 30 Initialize Method
The world of clara-rules (2)
Commentary: About the interface
About disconnect () of HttpURLConnection
About the function double-java
[Ruby] The role of subscripts in learning elements in arrays
[Grails] About the setting area and the setting items of application.yml
About the usefulness of monads from an object-oriented perspective
Talking about the merits of database bind variables ((1) Introduction)
About the problem of deadlock in parallel processing in gem'sprockets' 4.0
About Java method binding
About DI of Spring ①
About the ternary operator
The world of clara-rules (4)
The world of clara-rules (1)
About DI of Spring ②
definition of ruby method
The world of clara-rules (5)