Class: Factor::Common::DeepStruct
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Factor::Common::DeepStruct
- Defined in:
- lib/common/deep_struct.rb
Instance Method Summary collapse
- #[](idx) ⇒ Object
-
#initialize(hash = nil) ⇒ DeepStruct
constructor
A new instance of DeepStruct.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hash = nil) ⇒ DeepStruct
Returns a new instance of DeepStruct.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/common/deep_struct.rb', line 6 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
#[](idx) ⇒ Object
32 33 34 35 |
# File 'lib/common/deep_struct.rb', line 32 def [](idx) hash = marshal_dump hash[idx.to_sym] end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/common/deep_struct.rb', line 28 def inspect @hash_table.inspect end |
#to_h ⇒ Object
20 21 22 |
# File 'lib/common/deep_struct.rb', line 20 def to_h @hash_table end |
#to_s ⇒ Object
24 25 26 |
# File 'lib/common/deep_struct.rb', line 24 def to_s @hast_table.to_s end |