Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- documented/common/class_exts/hash.rb
Overview
Represents a collection of key-value pairs.
Class Method Summary collapse
-
.put(target, path, val) ⇒ Hash
Adds a value to the hash at the specified path.
Instance Method Summary collapse
-
#to_struct ⇒ OpenStruct
Converts the hash to an OpenStruct.
Class Method Details
.put(target, path, val) ⇒ Hash
Adds a value to the hash at the specified path.
17 18 19 20 21 22 23 24 |
# File 'documented/common/class_exts/hash.rb', line 17 def self.put(target, path, val) path = [path] unless path.is_a?(Array) fail ArgumentError, "path cannot be empty" if path.empty? root = target path.slice(0..-2).each { |key| target = target[key] ||= {} } target[path.last] = val root end |
Instance Method Details
#to_struct ⇒ OpenStruct
Converts the hash to an OpenStruct.
29 30 31 |
# File 'documented/common/class_exts/hash.rb', line 29 def to_struct OpenStruct.new self end |