Sha256: e438d2b144c6210560741cd16cc1bca113751ecb4de079c32064ded6b01ceea0

Contents?: true

Size: 449 Bytes

Versions: 2

Compression:

Stored size: 449 Bytes

Contents

module AttributedObjectHelpers
  class HashUtil
    def self.symbolize_keys(hash)
      new_hash = {}

      hash.each { |k, v|
        if k.respond_to?(:to_sym)
          new_hash[k.to_sym] = v
        else
          new_hash[k] = v
        end
      }

      return new_hash
    end
    
    def self.slice(hash, keys)
      selected_keys = keys & hash.keys
      Hash[ [selected_keys, hash.values_at(*selected_keys)].transpose]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
attributed_object-0.4.0 lib/attributed_object_helpers/hash_util.rb
attributed_object-0.3.1 lib/attributed_object_helpers/hash_util.rb