Class: DeepStruct
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- DeepStruct
- Defined in:
- lib/twitchy/dstruct.rb
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 17 18 19 20 21 22 23 |
# File 'lib/twitchy/dstruct.rb', line 4 def initialize(hash=nil) @table = {} @hash_table = {} if hash hash.each do |k,v| @table[k.to_sym] = v @table[k.to_sym] = v.map do |o| o.is_a?(Hash) ? self.class.new(o) : o end if v.is_a? Array @table[k.to_sym] = self.class.new(v) if v.is_a? Hash @hash_table[k.to_sym] = v new_ostruct_member(k) end end end |
Instance Method Details
#to_h ⇒ Object
25 26 27 |
# File 'lib/twitchy/dstruct.rb', line 25 def to_h @hash_table end |