Class: HSafe

Inherits:
Object
  • Object
show all
Defined in:
lib/vimamsa/util.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HSafe

Returns a new instance of HSafe.



57
58
59
60
# File 'lib/vimamsa/util.rb', line 57

def initialize(hash)
  @h = hash
  @a = []
end

Instance Method Details

#[](x) ⇒ Object



62
63
64
65
# File 'lib/vimamsa/util.rb', line 62

def [](x)
  @a << x
  return self
end

#valObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/vimamsa/util.rb', line 67

def val
  b = @a.reverse
  hh = @h
  while !b.empty?
    x = b.pop
    puts "x=#{x}"
    pp b
    ok = false
    if hh.class == Hash or hh.class == Array
      ok = true
    else
      if hh.methods.include?(:[])
        ok = true
      end
    end
    return nil if !ok
    if hh[x].nil?
      return nil
    else
      hh = hh[x]
    end
  end
  return hh
end