Class: Character

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_rankObject

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

#healthObject

Returns the value of attribute health.



11
12
13
# File 'lib/middle_earth_challenge_simulator.rb', line 11

def health
  @health
end

#nameObject (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_sObject



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