:age def initialize(name, dob) @name = name @dob = dob calculate_age end def to_s "Name #{name}, Age: #{age}" end private def calculate_age age = dob_to_age(dob) end end
= name @dob = dob calculate_age end def to_s "Name #{name}, Age: #{age}" end private def calculate_age age = dob_to_age(dob) # this is not an instance var end end
def to_s "Age: #{age}" "Age: #{self.age}" "Age: #{@age}" end private # Set the instance variable value def calculate_age age = dob_to_age(dob) # creates a local var self.age = dob_to_age(dob) # sends a message @age = dob_to_age(dob) # ignores the method end end Why are instance v@rs confusing?
value end def to_s "Name #{name}, Age: #{age}" end private def calculate_age age = dob_to_age(dob) # Why age = doesn’t # set the instance variable? end end