Class: Hash

Inherits:
Object show all
Defined in:
lib/mumukit/core/hash.rb

Instance Method Summary collapse

Instance Method Details

#amend(other) ⇒ Object



19
20
21
# File 'lib/mumukit/core/hash.rb', line 19

def amend(other)
  other.merge(self)
end

#diff(other) ⇒ Object



23
24
25
26
27
# File 'lib/mumukit/core/hash.rb', line 23

def diff(other)
  s1 = Set.new(self)
  s2 = Set.new(other)
  { deletions: (s1 - s2).to_h, additions: (s2 - s1).to_h }
end

#dig(key, *keys) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/mumukit/core/hash.rb', line 5

def dig(key, *keys)
  value = self[key]
  if !value.nil? && !keys.empty?
    value.dig(*keys)
  else
    value
  end
end

#to_structObject



15
16
17
# File 'lib/mumukit/core/hash.rb', line 15

def to_struct
  OpenStruct.new self
end