Skip to content

Commit 100c316

Browse files
committed
Remove monkey patches of Range#each and Range#step
Reverts rails#11474. For Range#each, Ruby raises the same error as did the monkey patch for an ActiveSupport::TimeWithZone boundary, there is no behavior change. For Range#step, Ruby versions < 3.4 raise the same error as did the monkey patch. Since Ruby >= 3.4, Range#step uses the #+ method on the boundary to generate range elements, which ActiveSupport::TimeWithZone implements. PR for more context: ruby/ruby#7444
1 parent ef4201c commit 100c316

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

activesupport/lib/active_support/core_ext/range.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
require "active_support/core_ext/range/conversions"
44
require "active_support/core_ext/range/compare_range"
55
require "active_support/core_ext/range/overlap"
6-
require "active_support/core_ext/range/each"

activesupport/lib/active_support/core_ext/range/each.rb

Lines changed: 0 additions & 24 deletions
This file was deleted.

activesupport/test/core_ext/range_ext_test.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,18 @@ def test_each_on_time_with_zone
253253
end
254254
end
255255

256-
def test_step_on_time_with_zone
257-
twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone["Eastern Time (US & Canada)"], Time.utc(2006, 11, 28, 10, 30))
258-
assert_raises TypeError do
259-
((twz - 1.hour)..twz).step(1) { }
256+
if RUBY_VERSION < "3.4"
257+
def test_step_on_time_with_zone
258+
twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone["Eastern Time (US & Canada)"], Time.utc(2006, 11, 28, 10, 30))
259+
assert_raises TypeError do
260+
((twz - 1.hour)..twz).step(1) { }
261+
end
262+
end
263+
else
264+
def test_step_on_time_with_zone
265+
twz = ActiveSupport::TimeWithZone.new(nil, ActiveSupport::TimeZone["Eastern Time (US & Canada)"], Time.utc(2006, 11, 28, 10, 30))
266+
267+
assert_equal [twz, twz + 15.minutes, twz + 30.minutes], (twz..).step(15.minutes).first(3)
260268
end
261269
end
262270

0 commit comments

Comments
 (0)