- In your own words, what is a Class?
- A class is a broad category that have specific attributes that help define what the class is.
- What is an attribute of a Class?
- Class attributes are shared commonalities of a class. Every instance of a class shares these common attributes.
- What is behavior of a Class?
- Behaviors define what a class can do and are defined as instance methods.
- In the space below, create a Dog class with at least 2 attributes and 2 behaviors:
class Dog
attr_accessor :name, :breed, :weight #define attributes
def initialize(name)
@name = name
end
def change_breed(breed) #method 1
@breed = breed
end
def change_weight(value) #method 2
@value = value
end
def get_info #method 3
p @name
p @breed
p @value
end
end
- How do you create an instance of a class?
hudson = Dog.new("Hudson")
- What questions do you still have about classes in Ruby?
- I need more practice on this subject. I do not have any specific questions about the concept, more on implementation.