Module: Gemmy::Patches::HashPatch::InstanceMethods::Bury
- Defined in:
- lib/gemmy/patches/hash_patch.rb
Overview
The opposite of Hash#dig Takes a list of keys followed by a value to set
Example:
a = {a: {b: {}} }
a.bury(:a, :b, :c, 0)
puts a[:a][:b][:c]
=> 0
Class Method Summary collapse
-
.bury(caller_hash, *args) ⇒ Object
The bury method, taking the input hash as a parameter.
Instance Method Summary collapse
Class Method Details
.bury(caller_hash, *args) ⇒ Object
The bury method, taking the input hash as a parameter
245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/gemmy/patches/hash_patch.rb', line 245 def self.bury(caller_hash, *args) if args.count < 2 raise ArgumentError.new("2 or more arguments required") elsif args.count == 2 caller_hash[args[0]] = args[1] else arg = args.shift caller_hash[arg] = {} unless caller_hash[arg] bury(caller_hash[arg], *args) unless args.empty? end caller_hash end |
Instance Method Details
#bury(*args) ⇒ Object
241 242 243 |
# File 'lib/gemmy/patches/hash_patch.rb', line 241 def bury *args Gemmy.patch("hash/i/bury").bury self, *args end |