Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/nice/hash/add_to_ruby.rb
Instance Method Summary collapse
-
#bury(where, value) ⇒ Object
Stores a value on the location indicated input: where: (Array) value examples: my_array.bury([3, 0], "doom") # array of array my_array.bury([2, 1, :original],"the value to set") #array of array of hash.
-
#json(*keys) ⇒ Object
In case of an array of json strings will return the keys specified.
Instance Method Details
#bury(where, value) ⇒ Object
Stores a value on the location indicated input: where: (Array) value examples: my_array.bury([3, 0], "doom") # array of array my_array.bury([2, 1, :original],"the value to set") #array of array of hash
71 72 73 74 75 76 77 |
# File 'lib/nice/hash/add_to_ruby.rb', line 71 def bury(where, value) me = self where[0..-2].each do |key| me = me[key] end me[where[-1]] = value end |
#json(*keys) ⇒ Object
In case of an array of json strings will return the keys specified. The keys need to be provided as symbols input: keys: 1 value with key or an array of keys In case the key supplied doesn't exist in the hash then it will be return nil for that one output: if keys given: a hash of (keys, values) or the value, if the key is found more than once in the json string, then it will be return a hash of arrays if no keys given, an empty hash
89 90 91 92 |
# File 'lib/nice/hash/add_to_ruby.rb', line 89 def json(*keys) json_string = "[#{join(',')}]" json_string.json(*keys) end |