Sha256: 16e71960ea4bbee6023a602e750d47ebf1a4bb52ef44a591422b6b5d2cbc1a52

Contents?: true

Size: 632 Bytes

Versions: 20

Compression:

Stored size: 632 Bytes

Contents

module Twitter
  module HashHelper
    # Return a new hash with all keys converted to symbols, as long as
    # they respond to +to_sym+.
    #
    #   { 'name' => 'Rob', 'years' => '28' }.symbolize_keys
    #   #=> { :name => "Rob", :years => "28" }
    def self.symbolize_keys(hash)
      hash.dup.symbolize_keys!
    end

    # Destructively convert all keys to symbols, as long as they respond
    # to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
    def self.symbolize_keys!(hash)
      hash.keys.each do |key|
        hash[(key.to_sym rescue key) || key] = hash.delete(key)
      end
      hash
    end
  end
end

Version data entries

20 entries across 20 versions & 4 rubygems

Version Path
twitter-text-1.12.0 lib/twitter-text/hash_helper.rb
twitter-text-1.11.0 lib/twitter-text/hash_helper.rb
twitter-text-1.10.0 lib/twitter-text/hash_helper.rb
twitter-text-1.9.2 lib/twitter-text/hash_helper.rb
twitter-text-1.9.1 lib/twitter-text/hash_helper.rb
twitter-text-1.9.0 lib/twitter-text/hash_helper.rb
twitter-text-1.8.0 lib/twitter-text/hash_helper.rb
twitter-text-1.7.0 lib/twitter-text/hash_helper.rb
twitter-text-1.6.4 lib/twitter-text/hash_helper.rb
twitter-text-relative-1.6.2.3 lib/twitter-text-relative/hash_helper.rb
twitter-text-relative-1.6.2.pre.3 lib/twitter-text-relative/hash_helper.rb
twitter-text-relative-1.6.2.2 lib/twitter-text-relative/hash_helper.rb
twitter-text-relative-1.6.2.1 lib/twitter-text/hash_helper.rb
twitter-text-1.6.3 lib/twitter-text/hash_helper.rb
twitter-text-1.6.2 lib/twitter-text/hash_helper.rb
ritter-0.0.91 lib/ritter-text/hash_helper.rb
ritter-0.0.90 lib/ritter-text/hash_helper.rb
ritter-0.0.89 lib/ritter-text/hash_helper.rb
ritter-0.0.88 lib/twitter-text/hash_helper.rb
twitter-text-editted-1.0.0 lib/twitter-text/hash_helper.rb