Class: DiscreteRange

Inherits:
Object
  • Object
show all
Defined in:
lib/ranges.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#maximumObject

Returns the value of attribute maximum.



27
28
29
# File 'lib/ranges.rb', line 27

def maximum
  @maximum
end

#minimumObject

Returns the value of attribute minimum.



27
28
29
# File 'lib/ranges.rb', line 27

def minimum
  @minimum
end

#valuesObject

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

#intervalObject



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