Class: Integer
Overview
Extensions to Integer needed to support flex array.
Instance Method Summary collapse
-
#to_index_range(spec) ⇒ Object
Convert this integer to a range index against the spec.
-
#to_spec_component(stride) ⇒ Object
Convert this integer to a limits component.
Instance Method Details
#to_index_range(spec) ⇒ Object
Convert this integer to a range index against the spec.
14 15 16 17 18 19 20 21 22 |
# File 'lib/flex_array/integer.rb', line 14 def to_index_range(spec) alter_ego = (self >= 0) ? self : (spec.max + self + 1) if spec === alter_ego alter_ego..alter_ego else fail IndexError, "Subscript out of range: #{self.inspect}" end end |
#to_spec_component(stride) ⇒ Object
Convert this integer to a limits component.
5 6 7 8 9 10 11 |
# File 'lib/flex_array/integer.rb', line 5 def to_spec_component(stride) if self >= 0 SpecComponent.new(0...self, stride) else fail ArgumentError, "Invalid flex array dimension: #{self.inspect}" end end |