Sha256: 7da982e253c23bcb283e3069046e8253181f80b0257dd1c9843fe37e88d167f1

Contents?: true

Size: 471 Bytes

Versions: 2

Compression:

Stored size: 471 Bytes

Contents

class Hash
  def symbolize_keys(&select)
    dup.symbolize_keys!(&select)
  end

  def symbolize_keys!(&select)
    if select
      keys.each do |key|
        if select[key]
          new_key = (key.to_sym rescue key.to_s.to_sym)
          self[new_key] = delete(key)
        end
      end
    else
      keys.each do |key|
        new_key = (key.to_sym rescue key.to_s.to_sym)
        self[new_key] = delete(key)
      end
    end
    self
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fozzie-1.1.0 lib/core_ext/hash/symbolize_keys.rb
fozzie-1.0.3 lib/core_ext/hash/symbolize_keys.rb