Sha256: c63d6fdcd8e01b311a1cf84e20a6db0ef60ec9294e4be5c8106b1020422d33f8

Contents?: true

Size: 739 Bytes

Versions: 33

Compression:

Stored size: 739 Bytes

Contents

# -*- encoding: utf-8 -*-

class ::Hash

  # Returns self with keys uncamelized and converted to symbols.
  def uncamelize_and_symbolize_keys
    self.uncamelize_and_stringify_keys.symbolize_keys
  end

  # Returns self with keys uncamelized and converted to strings.
  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

  # Returns self with all keys symbolized.
  def symbolize_keys
    symbolized = {}
    self.each_pair do |key, value|
      symbolized[key.to_sym] = value
    end

    symbolized
  end unless self.method_defined?(:symbolize_keys)

end # class Hash

Version data entries

33 entries across 31 versions & 2 rubygems

Version Path
stomp-1.4.10 lib/stomp/ext/hash.rb
stomp-1.4.9 lib/stomp/ext/hash.rb
stomp-1.4.8 lib/stomp/ext/hash.rb
stomp-1.4.7 lib/stomp/ext/hash.rb
stomp-1.4.6 lib/stomp/ext/hash.rb
stomp-1.4.5 lib/stomp/ext/hash.rb
stomp-1.4.4 lib/stomp/ext/hash.rb
stomp-1.4.3 lib/stomp/ext/hash.rb
stomp-1.4.2 lib/stomp/ext/hash.rb
stomp-1.4.1 lib/stomp/ext/hash.rb
stomp-1.4.0 lib/stomp/ext/hash.rb
stomp-1.3.5 lib/stomp/ext/hash.rb
stomp-1.3.4 lib/stomp/ext/hash.rb
stomp-1.3.3 lib/stomp/ext/hash.rb
stomp-1.3.2 lib/stomp/ext/hash.rb
stomp-1.3.1 lib/stomp/ext/hash.rb
stomp-1.3.0 lib/stomp/ext/hash.rb
stomp-1.2.16 lib/stomp/ext/hash.rb
stomp-1.2.14 lib/stomp/ext/hash.rb
stomp-1.2.13 lib/stomp/ext/hash.rb