Sha256: f9aac0068a78a737ea6e81b5b1425bf486e2ce36df024b6ec207c634f48a1d76

Contents?: true

Size: 336 Bytes

Versions: 3

Compression:

Stored size: 336 Bytes

Contents

class SliceableHash
 
  def initialize(hash)
    @hash = hash
  end

  # Return a hash that includes only the given keys.
  def slice(*keys)
    keys.map! { |key| @hash.convert_key(key) } if @hash.respond_to?(:convert_key, true)
    keys.each_with_object(@hash.class.new) { |k, hash| hash[k] = @hash[k] if @hash.has_key?(k) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
intercom-2.1.6 lib/ext/sliceable_hash.rb
intercom-2.1.5 lib/ext/sliceable_hash.rb
intercom-2.1.4 lib/ext/sliceable_hash.rb