Sha256: e016d9ebbe8374de80d983182e40473f416fd3695e08ac57ce9204d5fe89f4fc

Contents?: true

Size: 426 Bytes

Versions: 56

Compression:

Stored size: 426 Bytes

Contents

class Hash

  # Replace String keys in the current hash with symbol keys
  def keys_to_sym!
    new_hash = keys_to_sym
    self.clear
    new_hash.each do |k,v|
      self[k] = v
    end
  end

  def keys_to_sym
    symbolized_hash = {} 
    self.each do |k,v|
      if k =~ /\A[a-zA-Z0-9!?_]+\Z/
        symbolized_hash[k.to_sym] = v
      else
        symbolized_hash[k] = v
      end
    end
    symbolized_hash
  end

end

Version data entries

56 entries across 56 versions & 2 rubygems

Version Path
txcatcher-0.2.14 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.12 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.11 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.10 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.9 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.8 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.6 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.4 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.3 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.2 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.1 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.2.0 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.100 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.99 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.98 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.97 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.96 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.95 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.94 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.93 lib/txcatcher/utils/hash_string_to_sym_keys.rb