aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/range/each.rb
blob: 2d86997edfc283e40bf35660b2dfc29997d71b5e (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
# frozen_string_literal: true

require "active_support/time_with_zone"

module ActiveSupport
  module EachTimeWithZone #:nodoc:
    def each(&block)
      ensure_iteration_allowed
      super
    end

    def step(n = 1, &block)
      ensure_iteration_allowed
      super
    end

    private
      def ensure_iteration_allowed
        raise TypeError, "can't iterate from #{first.class}" if first.is_a?(TimeWithZone)
      end
  end
end

Range.prepend(ActiveSupport::EachTimeWithZone)