Module: Twitter::TwitterText::HashHelper
- Defined in:
- lib/twitter-text/hash_helper.rb
Class Method Summary collapse
-
.symbolize_keys(hash) ⇒ Object
Return a new hash with all keys converted to symbols, as long as they respond to
to_sym
. -
.symbolize_keys!(hash) ⇒ Object
Destructively convert all keys to symbols, as long as they respond to
to_sym
.
Class Method Details
.symbolize_keys(hash) ⇒ Object
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" }
13 14 15 |
# File 'lib/twitter-text/hash_helper.rb', line 13 def self.symbolize_keys(hash) symbolize_keys!(hash.dup) end |
.symbolize_keys!(hash) ⇒ Object
Destructively convert all keys to symbols, as long as they respond to to_sym
. Same as symbolize_keys
, but modifies self
.
19 20 21 22 23 24 |
# File 'lib/twitter-text/hash_helper.rb', line 19 def self.symbolize_keys!(hash) hash.keys.each do |key| hash[(key.to_sym rescue key) || key] = hash.delete(key) end hash end |