Class: Integer

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

Instance Method Summary collapse

Instance Method Details

#up_or_downto(limit) ⇒ Object

Iterates the given block, passing in increasing or decreasing values to and including limit

If no block is given, an Enumerator is returned instead.

Examples:

10.up_or_downto(12).to_a   # => [10, 11, 12]
10.upto(12).to_a           # => [10, 11, 12]
10.up_or_downto(8).to_a    # => [10, 9, 8]
10.downto(8).to_a          # => [10, 9, 8]


13
14
15
# File 'lib/core_ext/integer.rb', line 13

def up_or_downto(limit)
  self > limit ? self.downto(limit) : self.upto(limit)
end