Class: HSafe
- Inherits:
-
Object
- Object
- HSafe
- Defined in:
- lib/vimamsa/util.rb
Instance Method Summary collapse
- #[](x) ⇒ Object
-
#initialize(hash) ⇒ HSafe
constructor
A new instance of HSafe.
- #val ⇒ Object
Constructor Details
#initialize(hash) ⇒ HSafe
Returns a new instance of HSafe.
172 173 174 175 |
# File 'lib/vimamsa/util.rb', line 172 def initialize(hash) @h = hash @a = [] end |
Instance Method Details
#[](x) ⇒ Object
177 178 179 180 |
# File 'lib/vimamsa/util.rb', line 177 def [](x) @a << x return self end |
#val ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/vimamsa/util.rb', line 182 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 |