-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoop.rb
30 lines (24 loc) · 939 Bytes
/
oop.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Skillcrush 104 - Introducing Object Orientation
# create a class called Cat and give it attributes such as name, owner, and sound it makes
class Cat # when defining an object class, always capitalize the name
def set_name=(cat_name)
@name=cat_name # instance variable that belongs to this instance of the object - every Cat created will have an @name
end
def get_name
return @name # get_name method returns the Cat's name
end
def set_owner=(owner_name)
@owner_name=owner_name # set_name method sets every owner's name
end
def get_owner
return @owner_name # get_owner returns every owner's name
end
def sound
return "purrrrrrr" # defines what sound a Cat makes
end
end
# Write a sentence about your Cat using the new object
my_cat = Cat.new
my_cat.set_name= "Ella"
cat_name = my_cat.get_name
puts "#{cat_name} says #{my_cat.sound}"