Project

General

Profile

Feature #11747 ยป bury_examples.rb

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

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

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

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

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

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

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

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

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