aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/range/blockless_step.rb
blob: 98f333786d9dcd9a1d476acd2dda3104659d336a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Range
  if RUBY_VERSION < '1.9'
    # Return an array when step is called without a block.
    def step_with_blockless(value = 1, &block)
      if block_given?
        step_without_blockless(value, &block)
      else
        array = []
        step_without_blockless(value) { |step| array << step }
        array
      end
    end
  else
    def step_with_blockless(value = 1, &block) #:nodoc:
      if block_given?
        step_without_blockless
      else
        step_without_blockless(value).to_a
      end
    end
  end

  alias_method_chain :step, :blockless
end