ruby initialize method - purpose of initialize arguments

Im a bit confused on the initialize method. I understand that it is automatically called when you do Person.new and you add the arguments to it like Person.new("james"). What I dont understand is, why would you have instance variables in your initialize method that are not an used as an argument also. Is it so you can use them later on after the instance has been created? See below. What reason is there to have @age in the initialize method but not as an argument. thanks.

class Person

attr_accessor :name, :age

def initialize(name)
@name = name
@age = age
end


#ruby #oop

2 Likes2.20 GEEK