class SymbolHash
optionally, all String values are converted into Symbols.
A subclass of Hash where all keys are converted into Symbols, and
frozen_string_literal: true
def self.[](*hsh)
-
(SymbolHash)
- a new SymbolHash object -
(SymbolHash)
- a new SymbolHash from a hash object
Parameters:
-
list
(Array
) -- an even list of key followed by value -
hash
(Hash
) -- the hash object
Overloads:
-
[](*list)
-
[](hash)
def self.[](*hsh) obj = new if hsh.size == 1 && hsh.first.is_a?(Hash) hsh.first.each {|k, v| obj[k] = v } else 0.step(hsh.size, 2) {|n| obj[hsh[n]] = hsh[n + 1] } end obj end
def [](key) super(key.to_sym) end
-
(Object)
- the value associated with the key
Parameters:
-
key
(#to_sym
) -- the key to access
def [](key) super(key.to_sym) end
def []=(key, value)
-
value
(Object
) -- the value to be assigned. If this is a String and -
key
(#to_sym
) -- the key
def []=(key, value) super(key.to_sym, value.instance_of?(String) && @symbolize_value ? value.to_sym : value) end
def delete(key) super(key.to_sym) end
-
(void)
-
Parameters:
-
key
(#to_sym
) -- the key to delete
def delete(key) super(key.to_sym) end
def initialize(symbolize_value = true)
-
symbolize_value
(Boolean
) -- converts any String values into Symbols
def initialize(symbolize_value = true) @symbolize_value = symbolize_value end
def key?(key) super(key.to_sym) end
-
(Boolean)
- whether the key exists
Parameters:
-
key
(#to_sym
) -- the key to test
def key?(key) super(key.to_sym) end
def merge(hash) dup.merge!(hash) end
-
(SymbolHash)
- a new SymbolHash containing the merged data
Parameters:
-
hash
(Hash
) -- the hash of objects to copy
def merge(hash) dup.merge!(hash) end
def update(hash) hash.each {|k, v| self[k] = v }; self end
-
(SymbolHash)
- self
Parameters:
-
hash
(Hash
) -- the hash object to copy the values from
def update(hash) hash.each {|k, v| self[k] = v }; self end