Sha256: 6ba5529e7bd5eacb40be698e66189c2c1e9a98a8e8f4c5555756a124ad2f99b9

Contents?: true

Size: 725 Bytes

Versions: 1

Compression:

Stored size: 725 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stomp-1.2.5 lib/stomp/ext/hash.rb