Update shims for older rubies

`Symbol#name` and `Time#floor` are now present on the minimum required version.
This commit is contained in:
Jean Boussier 2024-01-05 17:04:05 +01:00
parent 1702b6cbfd
commit 6c357e9571
4 changed files with 4 additions and 16 deletions

@ -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

@ -108,12 +108,6 @@ def sec_fraction
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 (<tt>:hour</tt>, <tt>:min</tt>,
# <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>) reset cascadingly, so if only

@ -392,14 +392,8 @@ def to_proc
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)

@ -23,7 +23,7 @@ def initialize(message, name, alternatives)
super(message)
end
if !Exception.method_defined?(:detailed_message)
if !Exception.method_defined?(:detailed_message) # Ruby 3.2+
def detailed_message(...)
message
end