Sha256: dd449b87b5f15fecf94d6c6653d019f127b752c6f5ba3b90c3da14e56a19e54d

Contents?: true

Size: 1.08 KB

Versions: 30

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

# :nocov:

class Hash
  unless {}.respond_to?(:slice)
    def slice(*keys)
      keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
      keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if key?(k) }
    end
  end

  unless {}.respond_to?(:stringify_keys)
    def stringify_keys
      transform_keys(&:to_s)
    end
  end

  unless {}.respond_to?(:transform_keys)
    def transform_keys
      result = {}
      each_key do |key|
        result[yield(key)] = self[key]
      end
      result
    end
  end

  unless {}.respond_to?(:slice!)
    def slice!(*keys)
      keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
      omit = slice(*self.keys - keys)
      hash = slice(*keys)
      hash.default      = default
      hash.default_proc = default_proc if default_proc
      replace(hash)
      omit
    end
  end
end

class Array
  unless [].respond_to?(:extract_options!)
    def extract_options!
      if last.is_a?(Hash) && last.instance_of?(Hash)
        pop
      else
        {}
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-6.0.25 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.24 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.23 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.22 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.21 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.20 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.16 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.19 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.13 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.12 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.11 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.10 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.9 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.8 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.7 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.6 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.5 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.4 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.3 lib/sidekiq_unique_jobs/core_ext.rb
sidekiq-unique-jobs-6.0.2 lib/sidekiq_unique_jobs/core_ext.rb