lib/httpx/extensions.rb in httpx-0.21.1 vs lib/httpx/extensions.rb in httpx-0.22.0

- old
+ new

@@ -53,19 +53,21 @@ end Numeric.__send__(:include, NegMethods) end module NumericExtensions + # Ruby 2.4 backport refine Numeric do def infinite? self == Float::INFINITY end unless Numeric.method_defined?(:infinite?) end end module StringExtensions refine String do + # Ruby 2.5 backport def delete_suffix!(suffix) suffix = Backports.coerce_to_str(suffix) chomp! if frozen? len = suffix.length if len > 0 && index(suffix, -len) @@ -78,10 +80,11 @@ end end module HashExtensions refine Hash do + # Ruby 2.4 backport def compact h = {} each do |key, value| h[key] = value unless value == nil end @@ -91,11 +94,11 @@ end module ArrayExtensions module FilterMap refine Array do - + # Ruby 2.7 backport def filter_map return to_enum(:filter_map) unless block_given? each_with_object([]) do |item, res| processed = yield(item) @@ -105,19 +108,21 @@ end unless Array.method_defined?(:filter_map) end module Sum refine Array do + # Ruby 2.6 backport def sum(accumulator = 0, &block) values = block_given? ? map(&block) : self values.inject(accumulator, :+) end end unless Array.method_defined?(:sum) end module Intersect refine Array do + # Ruby 3.1 backport def intersect?(arr) if size < arr.size smaller = self else smaller, arr = arr, self @@ -128,10 +133,11 @@ end end module IOExtensions refine IO do + # Ruby 2.3 backport # provides a fallback for rubies where IO#wait isn't implemented, # but IO#wait_readable and IO#wait_writable are. def wait(timeout = nil, _mode = :read_write) r, w = IO.select([self], [self], nil, timeout) @@ -142,16 +148,18 @@ end end module RegexpExtensions refine(Regexp) do + # Ruby 2.4 backport def match?(*args) !match(*args).nil? end end end module URIExtensions + # uri 0.11 backport, ships with ruby 3.1 refine URI::Generic do def non_ascii_hostname @non_ascii_hostname end