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.1.92 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.91 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.90 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.89 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.88 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.87 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.86 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.85 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.84 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.83 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.82 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.81 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.80 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.79 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.78 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.77 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.76 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.75 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.74 lib/txcatcher/utils/hash_string_to_sym_keys.rb
txcatcher-0.1.73 lib/txcatcher/utils/hash_string_to_sym_keys.rb