Class: RubyOnAcid::SkipFactory
- Defined in:
- lib/rubyonacid/factories/skip.rb
Overview
Returns the minimum or the maximum at random (influenced by the given odds).
Instance Attribute Summary collapse
-
#odds ⇒ Object
The percentage odds that the factory will return 0 instead of 1.
Instance Method Summary collapse
-
#get_unit(key) ⇒ Object
If a random number between 0 and 1 is less than the assigned odds value, will return 0 (a “skip”).
-
#initialize(odds = 0.1) ⇒ SkipFactory
constructor
A new instance of SkipFactory.
Methods inherited from Factory
#boolean, #choose, #get, #within
Constructor Details
#initialize(odds = 0.1) ⇒ SkipFactory
Returns a new instance of SkipFactory.
11 12 13 14 |
# File 'lib/rubyonacid/factories/skip.rb', line 11 def initialize(odds = 0.1) super @odds = odds end |
Instance Attribute Details
#odds ⇒ Object
The percentage odds that the factory will return 0 instead of 1.
9 10 11 |
# File 'lib/rubyonacid/factories/skip.rb', line 9 def odds @odds end |
Instance Method Details
#get_unit(key) ⇒ Object
If a random number between 0 and 1 is less than the assigned odds value, will return 0 (a “skip”). Otherwise returns 1.
18 19 20 |
# File 'lib/rubyonacid/factories/skip.rb', line 18 def get_unit(key) rand < @odds ? 0.0 : 1.0 end |