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.



135
136
137
138
# File 'lib/vimamsa/util.rb', line 135

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

Instance Method Details

#[](x) ⇒ Object



140
141
142
143
# File 'lib/vimamsa/util.rb', line 140

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

#valObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/vimamsa/util.rb', line 145

def val
  b = @a.reverse
  hh = @h
  while !b.empty?
    x = b.pop
    debug "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