Class: Mondex::Species
- Inherits:
-
Object
- Object
- Mondex::Species
- Extended by:
- Concerns::Findable
- Defined in:
- lib/mondex/species.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#monsters ⇒ Object
readonly
Returns the value of attribute monsters.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #add_monster(monster) ⇒ Object
-
#initialize(name) ⇒ Species
constructor
A new instance of Species.
Methods included from Concerns::Findable
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
#monsters ⇒ Object (readonly)
Returns the value of attribute monsters.
4 5 6 |
# File 'lib/mondex/species.rb', line 4 def monsters @monsters end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/mondex/species.rb', line 3 def name @name end |
Class Method Details
.all ⇒ Object
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 |