Class: Range

Inherits:
Object show all
Defined in:
lib/accessibility/bridge/mri.rb

Overview

accessibility-core extensions to the Range class

Instance Method Summary collapse

Instance Method Details

#relative_to(max) ⇒ Range

Returns a new Range instance which has negative values in the receiver expanded relative to max

Examples:


(1..10).relative_to(10)   # => (1..10)
(-3..-1).relative_to(10)  # => (7..9)

Parameters:

  • max (Integer)

Returns:



211
212
213
214
215
216
# File 'lib/accessibility/bridge/mri.rb', line 211

def relative_to max
  beg = adjust_index self.begin, max
  len = adjust_index self.end, max
  len -= 1 if exclude_end?
  beg..len
end