LoginSignup
0
0

More than 3 years have passed since last update.

initializeメソッドとは

Last updated at Posted at 2020-10-07

initializeメソッドとは

インスタンスが生成される際、new メソッドの中で呼び出されるメソッドで

使い方としては

class User
  def initialize(user1, user2)
    @user1 = user1
    @user2 = user2
  end

  def response
    puts "#{@user1}さんの次が#{@user2}さんです"
  end
end

puts "最初に出てきた人は?"
friend1 = gets(chomp: true)
puts "次に出てきた人は?"
friend2 = gets(chomp: true)

answer = User.new(friend1, friend2)
answer.response

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0