Class: JTask::Get
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- JTask::Get
- Defined in:
- lib/jtask/get.rb
Overview
Allows nested OpenStructs, refer to andreapavoni.com/blog/2013/4/create-recursive-openstruct-from-a-ruby-hash Credits: Andrea Pavoni (DeepStruct guru)
Instance Method Summary collapse
-
#initialize(hash = nil) ⇒ Get
constructor
A new instance of Get.
- #to_h ⇒ Object
Constructor Details
#initialize(hash = nil) ⇒ Get
Returns a new instance of Get.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jtask/get.rb', line 18 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
29 30 31 |
# File 'lib/jtask/get.rb', line 29 def to_h @hash_table end |