Class: JTask::Get

Inherits:
OpenStruct
  • Object
show all
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

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_hObject



29
30
31
# File 'lib/jtask/get.rb', line 29

def to_h
  @hash_table
end