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