Class: Range

Inherits:
Object show all
Defined in:
lib/multiarray.rb

Overview

Range is extended with a few methods

Instance Method Summary collapse

Instance Method Details

#max_with_hornetseye ⇒ Object

For performance reasons a specialised method for integers is added

Returns:

  • (Object) —

    Maximum value of range.



549
550
551
552
553
554
555
# File 'lib/multiarray.rb', line 549

def max_with_hornetseye
  if self.end.is_a? Integer
    exclude_end? ? self.end - 1 : self.end
  else
    max_without_hornetseye
  end
end

#min_with_hornetseye ⇒ Object

For performance reasons a specialised method for integers is added

Returns:

  • (Object) —

    Minimum value of range.



534
535
536
537
538
539
540
# File 'lib/multiarray.rb', line 534

def min_with_hornetseye
  if self.begin.is_a? Integer
    self.begin
  else
    min_without_hornetseye
  end
end

#size ⇒ Integer

Compute the size of a range

Returns:

  • (Integer) —

    Number of discrete values within range.



562
563
564
# File 'lib/multiarray.rb', line 562

def size
  max + 1 - min
end