Sha256: 936ae58323cd4c205b8cdfdb7e876670b4e21e4b5a551fd0a94fa644cb3ad6f6

Contents?: true

Size: 633 Bytes

Versions: 18

Compression:

Stored size: 633 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)
      symbolize_keys!(hash.dup)
    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

18 entries across 16 versions & 2 rubygems

Version Path
tdiary-5.0.8 vendor/bundle/gems/twitter-text-1.14.7/lib/twitter-text/hash_helper.rb
twitter-text-2.0.2 lib/twitter-text/hash_helper.rb
twitter-text-2.0.1 lib/twitter-text/hash_helper.rb
twitter-text-2.0.0 lib/twitter-text/hash_helper.rb
twitter-text-1.14.7 lib/twitter-text/hash_helper.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/twitter-text-1.14.5/lib/twitter-text/hash_helper.rb
tdiary-5.0.5 vendor/bundle/gems/twitter-text-1.14.6/lib/twitter-text/hash_helper.rb
tdiary-5.0.5 vendor/bundle/gems/twitter-text-1.14.5/lib/twitter-text/hash_helper.rb
twitter-text-1.14.6 lib/twitter-text/hash_helper.rb
tdiary-5.0.4 vendor/bundle/gems/twitter-text-1.14.5/lib/twitter-text/hash_helper.rb
twitter-text-1.14.5 lib/twitter-text/hash_helper.rb
twitter-text-1.14.2 lib/twitter-text/hash_helper.rb
twitter-text-1.14.1 lib/twitter-text/hash_helper.rb
twitter-text-1.14.0 lib/twitter-text/hash_helper.rb
twitter-text-1.13.4 lib/twitter-text/hash_helper.rb
twitter-text-1.13.3 lib/twitter-text/hash_helper.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/twitter-text-1.13.0/lib/twitter-text/hash_helper.rb
twitter-text-1.13.0 lib/twitter-text/hash_helper.rb