Sha256: b4b861665c54ed36c85a06aae1269061eb130d631a9f7be1b51895625fcbeccb
Contents?: true
Size: 899 Bytes
Versions: 11
Compression:
Stored size: 899 Bytes
Contents
# frozen_string_literal: true # Please use this with at least the same consideration as you would when using OpenStruct. # Right now we only use this to parse our internal configuration files. It is not meant to # be used on incoming data. module Phobos class DeepStruct < OpenStruct # Based on # https://docs.omniref.com/ruby/2.3.0/files/lib/ostruct.rb#line=88 def initialize(hash = nil) @table = {} @hash_table = {} hash&.each_pair do |key, value| key = key.to_sym @table[key] = to_deep_struct(value) @hash_table[key] = value end end def to_h @hash_table.dup end alias to_hash to_h private def to_deep_struct(value) case value when Hash self.class.new(value) when Enumerable value.map { |el| to_deep_struct(el) } else value end end end end
Version data entries
11 entries across 11 versions & 1 rubygems