Class: DeepStruct
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- DeepStruct
- Defined in:
- lib/slnky/ext/deep_struct.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(hash = nil) ⇒ DeepStruct
constructor
A new instance of DeepStruct.
- #to_h ⇒ Object
Constructor Details
#initialize(hash = nil) ⇒ DeepStruct
Returns a new instance of DeepStruct.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/slnky/ext/deep_struct.rb', line 4 def initialize(hash=nil) @table = {} @hash_table = {} if hash hash.each do |k,v| @table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v) @hash_table[k.to_sym] = v new_ostruct_member(k) end end end |
Instance Method Details
#to_h ⇒ Object
18 19 20 |
# File 'lib/slnky/ext/deep_struct.rb', line 18 def to_h @hash_table end |