-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo03.rb
81 lines (63 loc) · 1.4 KB
/
demo03.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
module AbleToBreathUnderwater
def can_breath_underwater?
"Yes, I am able to breath underwater"
end
end
class Pet
attr_reader :name, :age
def initialize(name, age)
@name = name
@age = age
end
def breath
"inhale and exhale"
end
def eat
"with its mouth"
end
def speak
"soy mudo"
end
def to_s
"yo mismo"
end
end
class Cat < Pet
attr_reader :meows
def initialize(name, age, meows)
super(name, age) # llamando a initializer del padre.
@meows = meows
end
def speak
puts "meow"
super
end
def to_s
call "veterinario"
super
end
end
class Dog < Pet
attr_reader :barks
def initialize(name, age, barks)
super(name, age)
@barks = barks
end
def speak
"guao guao"
puts super
end
end
# irb(main):008:0> cat_lucy = Cat.new "Lucy", 3, true
# => #<Cat:0x00007faefc1cced0 @age=3, @meows=true, @name="Lucy">
# irb(main):009:0> dog_fido = Dog.new "Fido", 5, false
# => #<Dog:0x00007faefc3d6460 @age=5, @barks=false, @name="Fido">
# irb(main):010:0> dog_firulais = Dog.new "Firulais", 2, true
# => #<Dog:0x00007faefc37e738 @age=2, @barks=true, @name="Firulais">
class Fish < Pet
include AbleToBreathUnderwater
end
# irb(main):012:0> fish_querty = Fish.new "qwerty", 2
# => #<Fish:0x00007fa576088810 @age=2, @name="qwerty">
# irb(main):015:0> fish_querty.can_breath_underwater
# => "is able to breath underwater"