Class: Libis::Tools::DeepStruct

Inherits:
RecursiveOpenStruct
  • Object
show all
Defined in:
lib/libis/tools/deep_struct.rb

Overview

A class that derives from OpenStruct through the RecursiveOpenStruct. A RecursiveOpenStruct is derived from stdlib’s OpenStruct, but can be made recursive. DeepStruct enforces this behaviour and adds a clear! method.

Direct Known Subclasses

ConfigFile

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}, opts = {}) ⇒ DeepStruct

Returns a new instance of DeepStruct.



11
12
13
14
15
16
# File 'lib/libis/tools/deep_struct.rb', line 11

def initialize(hash = {}, opts = {})
  hash = {} unless hash
  opts = {} unless opts
  hash = {default: hash} unless hash.is_a? Hash
  super(hash, {recurse_over_arrays: true}.merge(opts))
end

Instance Method Details

#clear!Object

Delete all data fields



19
20
21
22
# File 'lib/libis/tools/deep_struct.rb', line 19

def clear!
  @table.keys.each { |key| delete_field(key) }
  @sub_elements = {}
end