blob: 90432b504dce86a9845e47590635f8d2c8b622cc (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# frozen_string_literal: true
module NanoBot
module Logic
module Helpers
module Hash
def self.symbolize_keys(object)
case object
when ::Hash
object.each_with_object({}) do |(key, value), result|
result[key.to_sym] = symbolize_keys(value)
end
when Array
object.map { |e| symbolize_keys(e) }
else
object
end
end
def self.fetch(object, path)
node = object
return nil unless node
path.each do |key|
unless node.is_a?(::Hash)
node = nil
break
end
node = node[key]
break if node.nil?
end
node
end
end
end
end
end
|