Sha256: e5de3c2e8f1b7050f11ac754ceb3716033b8d1f127c881ddf975a7785bb01808

Contents?: true

Size: 842 Bytes

Versions: 1

Compression:

Stored size: 842 Bytes

Contents

# frozen_string_literal: true

unless { a: 1 }.respond_to?(:fetch_values)
  # Add fetch_values if this version of ruby does not define it.
  class Hash
    def fetch_values(*keys)
      keys.map do |k|
        if block_given?
          yield(self[k])
        else
          self[k]
        end
      end
    end
  end
end

unless ''.respond_to?(:match?)
  # Add String#match? to pre-2.4 ruby
  class String
    def match?(regexp)
      self =~ regexp
    end
  end
end

unless //.respond_to?(:match?)
  # Add Regexp#match? to pre-2.4 ruby
  class Regexp
    def match?(str)
      self =~ str
    end
  end
end

unless ''.respond_to?(:strip_heredoc)
  # Patch String to provide heredocs with whitespace stripped
  class String
    def strip_heredoc
      indent = chomp.scan(/^\s*/).min.size
      gsub(/^\s{#{indent}}/, '')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fat_table-0.9.8 lib/fat_table/patches.rb