Class: Zyps::PopulationLimit
- Inherits:
-
EnvironmentalFactor
- Object
- EnvironmentalFactor
- Zyps::PopulationLimit
- Defined in:
- lib/zyps/environmental_factors.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Maximum allowed population.
Instance Method Summary collapse
-
#act(environment) ⇒ Object
Remove target if there are too many objects in environment.
-
#initialize(count) ⇒ PopulationLimit
constructor
A new instance of PopulationLimit.
Constructor Details
#initialize(count) ⇒ PopulationLimit
Returns a new instance of PopulationLimit.
172 173 174 |
# File 'lib/zyps/environmental_factors.rb', line 172 def initialize(count) self.count = count end |
Instance Attribute Details
#count ⇒ Object
Maximum allowed population.
170 171 172 |
# File 'lib/zyps/environmental_factors.rb', line 170 def count @count end |
Instance Method Details
#act(environment) ⇒ Object
Remove target if there are too many objects in environment.
177 178 179 180 |
# File 'lib/zyps/environmental_factors.rb', line 177 def act(environment) excess = environment.objects.length - @count environment.objects.slice!(0, excess) if excess > 0 end |