Project

General

Profile

Feature #11747 ยป bury_examples.rb

briankung (Brian Kung), 05/17/2018 04:36 PM

 
[].bury(:users, 0, :name, 'Matz') { Hash.new }
#=> [{:users => {0 => {name => 'Matz'}}}]

[].bury(:users, 0, :name, 'Matz') { Array.new }
# ^ error here
#=> TypeError (no implicit conversion of Symbol into Integer)

[].bury(0, 0, 1, 'Matz') { Array.new }
#=> [[[nil,'Matz']]]

[].bury(:users, :zero, :name, 'Matz') { |next_arg| Struct.new(next_arg).new }
#=> [#<struct users=#<struct zero=#<struct name="Matz">>>]

[].bury(:users, 0, :name, 'Matz') { |next_arg| Struct.new(next_arg).new }
# ^ error here
#=> TypeError (no implicit conversion of Integer into String)

{users: {0 => {}}}.bury(:users, 0, :name, 'Matz')
# {:users => {0 => {:name => 'Matz'}}}

{users: {0 => nil}}.bury(:users, 0, :name, 'Matz') { |next_arg| Struct.new(next_arg).new }
# {:users => {0 => #<struct name="Matz">}}
#
# If the one of the retrieved values is nil, in this case {0 => nil},
# should #bury overwrite it?

[{users: ['skipped']}].bury(:users, 1, :name, 'Matz') { Hash.new }
# [{:users => ['skipped', {:name => 'Matz'}]}]
    (1-1/1)