From 6c357e9571c782652e65dad42b659a2f5475a8a5 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Fri, 5 Jan 2024 17:04:05 +0100 Subject: [PATCH] Update shims for older rubies `Symbol#name` and `Time#floor` are now present on the minimum required version. --- .../lib/active_support/core_ext/range/overlap.rb | 2 +- .../lib/active_support/core_ext/time/calculations.rb | 6 ------ .../lib/active_support/hash_with_indifferent_access.rb | 10 ++-------- railties/lib/rails/command.rb | 2 +- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/range/overlap.rb b/activesupport/lib/active_support/core_ext/range/overlap.rb index 07215776a70..b08cdb39cfa 100644 --- a/activesupport/lib/active_support/core_ext/range/overlap.rb +++ b/activesupport/lib/active_support/core_ext/range/overlap.rb @@ -4,7 +4,7 @@ class Range # Compare two ranges and see if they overlap each other # (1..5).overlap?(4..6) # => true # (1..5).overlap?(7..9) # => false - unless Range.method_defined?(:overlap?) + unless Range.method_defined?(:overlap?) # Ruby 3.3+ def overlap?(other) raise TypeError unless other.is_a? Range diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 1176c5a5e77..67973f7f43a 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -108,12 +108,6 @@ class Time subsec end - unless Time.method_defined?(:floor) - def floor(precision = 0) - change(nsec: 0) + subsec.floor(precision) - end - end - # Returns a new Time where one or more of the elements have been changed according # to the +options+ parameter. The time options (:hour, :min, # :sec, :usec, :nsec) reset cascadingly, so if only diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 1b1af671151..521cdf6a438 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -392,14 +392,8 @@ module ActiveSupport end private - if Symbol.method_defined?(:name) - def convert_key(key) - key.kind_of?(Symbol) ? key.name : key - end - else - def convert_key(key) - key.kind_of?(Symbol) ? key.to_s : key - end + def convert_key(key) + key.kind_of?(Symbol) ? key.name : key end def convert_value(value, conversion: nil) diff --git a/railties/lib/rails/command.rb b/railties/lib/rails/command.rb index f84d2feeca7..92dcf6a1254 100644 --- a/railties/lib/rails/command.rb +++ b/railties/lib/rails/command.rb @@ -23,7 +23,7 @@ module Rails super(message) end - if !Exception.method_defined?(:detailed_message) + if !Exception.method_defined?(:detailed_message) # Ruby 3.2+ def detailed_message(...) message end