Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/stomp/ext/hash.rb

Instance Method Summary collapse

Instance Method Details

#symbolize_keysObject

Returns self with all keys symbolized.



22
23
24
25
26
27
28
29
# File 'lib/stomp/ext/hash.rb', line 22

def symbolize_keys
  symbolized = {}
  self.each_pair do |key, value|
    symbolized[key.to_sym] = value
  end

  symbolized
end

#uncamelize_and_stringify_keysObject

Returns self with keys uncamelized and converted to strings.



11
12
13
14
15
16
17
18
19
# File 'lib/stomp/ext/hash.rb', line 11

def uncamelize_and_stringify_keys
  uncamelized = {}
  self.each_pair do |key, value|
    new_key = key.to_s.split(/(?=[A-Z])/).join('_').downcase
    uncamelized[new_key] = value
  end

  uncamelized
end

#uncamelize_and_symbolize_keysObject

Returns self with keys uncamelized and converted to symbols.



6
7
8
# File 'lib/stomp/ext/hash.rb', line 6

def uncamelize_and_symbolize_keys
  self.uncamelize_and_stringify_keys.symbolize_keys
end