Class: Mondex::Species

Inherits:
Object
  • Object
show all
Extended by:
Concerns::Findable
Defined in:
lib/mondex/species.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Findable

find_by_name

Constructor Details

#initialize(name) ⇒ Species

Returns a new instance of Species.



8
9
10
11
12
# File 'lib/mondex/species.rb', line 8

def initialize(name)
  @name = name
  @monsters = []
  @@all << self
end

Instance Attribute Details

#monstersObject (readonly)

Returns the value of attribute monsters.



4
5
6
# File 'lib/mondex/species.rb', line 4

def monsters
  @monsters
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/mondex/species.rb', line 3

def name
  @name
end

Class Method Details

.allObject



18
19
20
# File 'lib/mondex/species.rb', line 18

def self.all
  @@all.sort_by {|s| s.name}
end

.create_or_find_by_name(species_name) ⇒ Object



22
23
24
# File 'lib/mondex/species.rb', line 22

def self.create_or_find_by_name(species_name)
  self.find_by_name(species_name) || self.new(species_name)
end

Instance Method Details

#add_monster(monster) ⇒ Object



14
15
16
# File 'lib/mondex/species.rb', line 14

def add_monster(monster)
  @monsters << monster
end