class I18n::JS::Private::HashWithSymbolKeys

Hash with string keys converted to symbol keys Used for handling values read on YAML

@api private

Public Class Methods

new(hash) click to toggle source

An instance can only be created by passing in another hash

# File lib/i18n/js/private/hash_with_symbol_keys.rb, line 11
def initialize(hash)
  raise TypeError unless hash.is_a?(::Hash)

  hash.each_key do |key|
    # Objects like `Integer` does not have `to_sym`
    new_key = key.respond_to?(:to_sym) ? key.to_sym : key
    self[new_key] = hash[key]
  end

  self.default = hash.default if hash.default
  self.default_proc = hash.default_proc if hash.default_proc

  freeze
end

Public Instance Methods

slice(*keys) click to toggle source

From AS Core extension

# File lib/i18n/js/private/hash_with_symbol_keys.rb, line 27
def slice(*keys)
  hash = keys.each_with_object(Hash.new) do |k, hash|
    hash[k] = self[k] if has_key?(k)
  end
  self.class.new(hash)
end