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-3.7.2 lib/ext/sliceable_hash.rb
intercom-3.7.1 lib/ext/sliceable_hash.rb
intercom-3.7.0 lib/ext/sliceable_hash.rb
intercom-3.6.2 lib/ext/sliceable_hash.rb
intercom-3.6.1 lib/ext/sliceable_hash.rb
intercom-3.6.0 lib/ext/sliceable_hash.rb
intercom-3.5.26 lib/ext/sliceable_hash.rb
intercom-3.5.25 lib/ext/sliceable_hash.rb
intercom-3.5.24 lib/ext/sliceable_hash.rb
intercom-3.5.23 lib/ext/sliceable_hash.rb
intercom-3.5.22 lib/ext/sliceable_hash.rb
intercom-3.5.21 lib/ext/sliceable_hash.rb
intercom-3.5.20 lib/ext/sliceable_hash.rb
intercom-3.5.19 lib/ext/sliceable_hash.rb
intercom-3.5.17 lib/ext/sliceable_hash.rb
intercom-3.5.16 lib/ext/sliceable_hash.rb
intercom-3.5.15 lib/ext/sliceable_hash.rb
intercom-3.5.14 lib/ext/sliceable_hash.rb
intercom-3.5.12 lib/ext/sliceable_hash.rb
intercom-3.5.11 lib/ext/sliceable_hash.rb