What is a class?
a class is a blueprint from which individual objects of the same class are created.
how do you create a class?
to create a class we use the class keyword the name of a class must begin with a capital letter we can define methods within a class
how do you create a new instance of class?
by doing [class_name].new
what gets executed when you call Class.new?
the defined initialized method is what gets executed
what is a getter method?
a getter method is used to refer to the value of the attribute you assigned it to.
class Cat
def initialize(name, color, age)
@name = name
@color = color
@age = age
enddef get_name
@name
end
end
cat_1 = Cat.new(“Sennacy”, “brown”, 3)
p cat_1.get_name # “Sennacy”
what is a setter method?
we use them to modify the @attribute
class Cat
def initialize(name, color, age)
@name = name
@color = color
@age = age
end
# getter
def age
@age
end
# setter
def age=(number)
@age = number
end
endcat_1 = Cat.new(“Sennacy”, “brown”, 3)
p cat_1 #
cat_1.age = 42
p cat_1 #