-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgood_guy_homework.rb
More file actions
122 lines (85 loc) · 2.24 KB
/
good_guy_homework.rb
File metadata and controls
122 lines (85 loc) · 2.24 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class Person
attr_accessor(:first_name, :last_name , :occupation)
#attr_accessor does both attr_read & attr_witer does
# attr_reader :first_name, :last_name, :occupation
# attr_writer :first_name, :last_name, :occupation
def initialize (first_name, last_name, occupation)
@first_name = first_name
@last_name = last_name
@occupation = occupation
end
#normal method
# def first_name
# return @first_name
# end
#setter method
# def first_name=(new_name)
# @first_name = new_name
# end
#
# def last_name=(new_name)
# @last_name = new_name
# end
#
# def occupation=(new_name)
# @occupation = new_name
# end
#===================
def list_attributes
"#{@occupation}
#{@first_name}
#{@last_name}"
end
end
# this is a instance
good_guy = Person.new("Jim", "Gordan", "Detective")
#creating space for terminal
puts ""
#========================
#This is a getter ie it gives us the first_name ie "jim"
# puts good_guy.first_name
#====================
#creating space for terminal
puts ""
#========================
# good_guy.first_name = "James"
# good_guy.last_name = "Gordon"
# good_guy.occupation = "Commissioner"
# puts good_guy.list_attributes
#creating space for terminal
puts ""
#========================
#this called a Inheritance class ie = class Superhero < Person
class Superhero < Person
#adding super power & hero name to inherited infro from Person
#class
attr_accessor :super_power, :hero_name
def initialize(first_name, last_name, occupation, super_power)
super(first_name, last_name, occupation)
@hero_name = @occupation
@super_power = super_power
end
def secret_identity
"#{@first_name} #{@last_name}"
end
end
# this is a instance
batman = Superhero.new("Bruce", "Wayne", "Batman","'Bat like instincts'")
#===============================================
puts "The Good Guy In This Story is..."
puts ""
puts good_guy.list_attributes
puts ""
puts "The Superhero is... "
puts ""
puts "#{batman.occupation}"
puts ""
puts "Batman's #{batman.super_power} help him to protect the city that he Loves"
puts ""
puts "But Little does Gotham know that Batman is really..."
puts ""
puts "#{batman.secret_identity}"
puts ""
puts ""
puts ""
# puts batman.secret_identity