Class: DiscreteRange
- Inherits:
-
Object
- Object
- DiscreteRange
- 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.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
- #index(element) ⇒ Object
-
#initialize(v) ⇒ DiscreteRange
constructor
A new instance of DiscreteRange.
- #interval ⇒ Object
- #run(interval) ⇒ Object
Constructor Details
#initialize(v) ⇒ DiscreteRange
Returns a new instance of DiscreteRange.
29 30 31 32 33 |
# File 'lib/ranges.rb', line 29 def initialize(v) @values = v[:values] @minimum = @values.first @maximum = @values.last end |
Instance Attribute Details
#maximum ⇒ Object
Returns the value of attribute maximum.
27 28 29 |
# File 'lib/ranges.rb', line 27 def maximum @maximum end |
#minimum ⇒ Object
Returns the value of attribute minimum.
27 28 29 |
# File 'lib/ranges.rb', line 27 def minimum @minimum end |
#values ⇒ Object
Returns the value of attribute values.
28 29 30 |
# File 'lib/ranges.rb', line 28 def values @values end |
Instance Method Details
#index(element) ⇒ Object
39 40 41 |
# File 'lib/ranges.rb', line 39 def index(element) @values.index(element) end |
#interval ⇒ Object
35 36 37 |
# File 'lib/ranges.rb', line 35 def interval @values.count end |
#run(interval) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/ranges.rb', line 43 def run(interval) current = 0 while(current <= @values.count - 1) yield(current,@values[current]) current += interval end end |