What is the initialize method?
In the method called in the new
method when the instance is created
As a usage
class User
def initialize(user1, user2)
@user1 = user1
@user2 = user2
end
def response
puts "#{@user1}Next is#{@user2}Mr. is"
end
end
puts "Who came out first?"
friend1 = gets(chomp: true)
puts "Who came out next?"
friend2 = gets(chomp: true)
answer = User.new(friend1, friend2)
answer.response
Recommended Posts