Class: Hash

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

Direct Known Subclasses

SDP::Description

Instance Method Summary collapse

Instance Method Details

#keys_to_sHash

Converts keys to Strings. Useful for dealing with SDP::Parser results (which subclasses Parslet::Parser), which returns Parslet::Slice objects in place of String objects, which isn’t helpful in this case.

Returns:

  • (Hash)

    self, but with Strings instead of Parslet::Slices.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ext/hash_patch.rb', line 7

def keys_to_s
  self.each do |k, v|
    case v
    when Hash
      v.keys_to_s
    when Array
      v.each do |element|
        element.keys_to_s if element.is_a? Hash
      end
    else
      self[k] = v.to_s
    end
  end

  self
end