Class: OpenVar

Inherits:
Object
  • Object
show all
Defined in:
lib/exper/varmint.rb

Instance Method Summary collapse

Constructor Details

#initializeOpenVar

Returns a new instance of OpenVar.



15
16
17
18
# File 'lib/exper/varmint.rb', line 15

def initialize
  @hash = {}
  @obj = OpenStruct.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



34
35
36
37
38
# File 'lib/exper/varmint.rb', line 34

def method_missing(meth, *args)
  setter = meth.to_s + "="
  meh = @obj.send(setter, OpenStruct.new)
  @obj
end

Instance Method Details

#[](var) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/exper/varmint.rb', line 20

def [](var)
puts "self = #{self.inspect}"
#   @hash[var] = nil
  pieces = var.split(".")
  this = @obj
  pieces.each do |piece|
puts "piece = #{piece}"
#     this.send(piece.to_s+"=", OpenStruct.new)
    this = this.send(piece)
puts "this = #{this.inspect}"
  end
  this
end