Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/rubytter/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#stringify_keysObject



2
3
4
5
6
7
# File 'lib/rubytter/core_ext.rb', line 2

def stringify_keys
  inject({}) do |options, (key, value)|
    options[key.to_s] = value
    options
  end
end

#stringify_keys!Object



9
10
11
12
13
14
# File 'lib/rubytter/core_ext.rb', line 9

def stringify_keys!
  keys.each do |key|
    self[key.to_s] = delete(key)
  end
  self
end

#symbolize_keysObject



16
17
18
19
20
21
# File 'lib/rubytter/core_ext.rb', line 16

def symbolize_keys
  inject({}) do |options, (key, value)|
    options[(key.to_sym rescue key) || key] = value
    options
  end
end

#symbolize_keys!Object



23
24
25
# File 'lib/rubytter/core_ext.rb', line 23

def symbolize_keys!
  self.replace(self.symbolize_keys)
end