Class: ContinuousRange
- Inherits:
-
Object
- Object
- ContinuousRange
- Defined in:
- lib/ranges.rb
Instance Attribute Summary collapse
-
#maximum ⇒ Object
Returns the value of attribute maximum.
-
#minimum ⇒ Object
Returns the value of attribute minimum.
Instance Method Summary collapse
- #index(element) ⇒ Object
-
#initialize(range) ⇒ ContinuousRange
constructor
A new instance of ContinuousRange.
- #interval ⇒ Object
- #run(interval) ⇒ Object
Constructor Details
#initialize(range) ⇒ ContinuousRange
Returns a new instance of ContinuousRange.
4 5 6 7 |
# File 'lib/ranges.rb', line 4 def initialize(range) @minimum = range[:minimum] @maximum = range[:maximum] end |
Instance Attribute Details
#maximum ⇒ Object
Returns the value of attribute maximum.
2 3 4 |
# File 'lib/ranges.rb', line 2 def maximum @maximum end |
#minimum ⇒ Object
Returns the value of attribute minimum.
2 3 4 |
# File 'lib/ranges.rb', line 2 def minimum @minimum end |
Instance Method Details
#index(element) ⇒ Object
13 14 15 |
# File 'lib/ranges.rb', line 13 def index(element) element.to_f end |
#interval ⇒ Object
9 10 11 |
# File 'lib/ranges.rb', line 9 def interval @maximum - @minimum end |
#run(interval) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ranges.rb', line 17 def run(interval) current = @minimum while(current <= @maximum) yield(current,current) current += interval end end |