Class: Character
- Inherits:
-
Object
- Object
- Character
- Includes:
- Comparable
- Defined in:
- lib/middle_earth_challenge_simulator.rb
Overview
Middle Earth Challenge Simulator Copyright (C) 2008, Chesley Coughlin WEEK 8 Homework
Constant Summary collapse
- MAX_HEALTH =
100
Instance Attribute Summary collapse
-
#challenge_rank ⇒ Object
Returns the value of attribute challenge_rank.
-
#health ⇒ Object
Returns the value of attribute health.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(c) ⇒ Object
-
#initialize(n, c, h) ⇒ Character
constructor
A new instance of Character.
- #to_s ⇒ Object
Constructor Details
#initialize(n, c, h) ⇒ Character
Returns a new instance of Character.
13 14 15 16 17 |
# File 'lib/middle_earth_challenge_simulator.rb', line 13 def initialize (n, c, h) @name = n @challenge_rank = c @health = h end |
Instance Attribute Details
#challenge_rank ⇒ Object
Returns the value of attribute challenge_rank.
10 11 12 |
# File 'lib/middle_earth_challenge_simulator.rb', line 10 def challenge_rank @challenge_rank end |
#health ⇒ Object
Returns the value of attribute health.
11 12 13 |
# File 'lib/middle_earth_challenge_simulator.rb', line 11 def health @health end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/middle_earth_challenge_simulator.rb', line 11 def name @name end |
Instance Method Details
#<=>(c) ⇒ Object
29 30 31 |
# File 'lib/middle_earth_challenge_simulator.rb', line 29 def <=> c return self.challenge_rank <=> c.challenge_rank end |
#to_s ⇒ Object
24 25 26 27 |
# File 'lib/middle_earth_challenge_simulator.rb', line 24 def to_s "Character {name: #{self.name} challenge_rank: #{self.challenge_rank} " \ "health: #{self.health}}" end |