class Integer
Public Instance Methods
up_or_downto(limit)
click to toggle source
Iterates the given block, passing in increasing or decreasing values to and including limit
If no block is given, an Enumerator is returned instead.
@example
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]
# File lib/core_ext/integer.rb 13 def up_or_downto(limit) 14 self > limit ? self.downto(limit) : self.upto(limit) 15 end