Sha256: 1d5ab0347b2bf0ca7fcbc9aa117d0bbb1921590ef030689a95c7216a1586f4af

Contents?: true

Size: 583 Bytes

Versions: 4

Compression:

Stored size: 583 Bytes

Contents

class Hash
  # 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.
  #
  # @return [Hash] +self+, but with Strings instead of Parslet::Slices.
  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sdp-0.2.9 lib/ext/hash_patch.rb
sdp-0.2.8 lib/ext/hash_patch.rb
sdp-0.2.7 lib/ext/hash_patch.rb
sdp-0.2.6 lib/ext/hash_patch.rb