aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/range/each.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/range/each.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/range/each.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/range/each.rb b/activesupport/lib/active_support/core_ext/range/each.rb
new file mode 100644
index 0000000000..2f22cd0e92
--- /dev/null
+++ b/activesupport/lib/active_support/core_ext/range/each.rb
@@ -0,0 +1,25 @@
+# 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)