Module: HierarchicalConfig::ConfigStruct

Extended by:
T::Sig
Includes:
Kernel
Defined in:
lib/hierarchical_config.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



58
59
60
# File 'lib/hierarchical_config.rb', line 58

def [](key)
  send(key)
end

#to_h(&blk) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/hierarchical_config.rb', line 42

def to_h(&blk)
  hash = self.class.props.keys.map{|key| [key, send(key)]}
  if blk
    # copied from https://github.com/marcandre/backports/blob/36572870cbdc0cda30e5bab81af8ba390a6cf7c7/lib/backports/2.6.0/hash/to_h.rb#L3C39-L3C39
    # to implement to_h with block for ruby < 2.6.0
    if {n: true}.to_h{[:ok, true]}[:n]
      T.unsafe(hash).map(&blk).to_h
    else
      hash.to_h(&blk)
    end
  else
    hash.to_h
  end
end

#to_hashObject



23
24
25
# File 'lib/hierarchical_config.rb', line 23

def to_hash
  Hash[self.class.props.keys.map{|key| [key, item_to_hash(send(key))]}] # rubocop:disable Style/HashConversion
end