Class: I18n::JS::Private::HashWithSymbolKeys Private

Inherits:
Hash
  • Object
show all
Defined in:
lib/i18n/js/private/hash_with_symbol_keys.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HashWithSymbolKeys

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

An instance can only be created by passing in another hash

Raises:

  • (TypeError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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

Instance Method Details

#slice(*keys) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

From AS Core extension



27
28
29
30
31
32
# 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