Sha256: 05a8e5cc11e5e972ee3f33ca800d64c9c92781eab1ac38bacac78d3ce81188b9

Contents?: true

Size: 455 Bytes

Versions: 74

Compression:

Stored size: 455 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) && if_string_not_empty(@hash[k]) }
  end
  
  def if_string_not_empty(val)
    val.kind_of?(String) ? !val.empty? : true
  end
end

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
intercom-4.2.1 lib/ext/sliceable_hash.rb
intercom-4.2.0 lib/ext/sliceable_hash.rb
intercom-4.1.3 lib/ext/sliceable_hash.rb
intercom-4.1.2 lib/ext/sliceable_hash.rb
intercom-4.1.1 lib/ext/sliceable_hash.rb
intercom-4.1.0 lib/ext/sliceable_hash.rb
intercom-4.0.1 lib/ext/sliceable_hash.rb
intercom-4.0.0 lib/ext/sliceable_hash.rb
intercom-3.9.5 lib/ext/sliceable_hash.rb
intercom-3.9.4 lib/ext/sliceable_hash.rb
intercom-3.9.3 lib/ext/sliceable_hash.rb
intercom-3.9.2 lib/ext/sliceable_hash.rb
intercom-3.9.0 lib/ext/sliceable_hash.rb
intercom-3.8.1 lib/ext/sliceable_hash.rb
intercom-3.8.0 lib/ext/sliceable_hash.rb
intercom-3.7.7 lib/ext/sliceable_hash.rb
intercom-3.7.6 lib/ext/sliceable_hash.rb
intercom-3.7.5 lib/ext/sliceable_hash.rb
intercom-3.7.4 lib/ext/sliceable_hash.rb
intercom-3.7.3 lib/ext/sliceable_hash.rb