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.
159 160 161 162 |
# File 'lib/vimamsa/util.rb', line 159 def initialize(hash) @h = hash @a = [] end |
Instance Method Details
#[](x) ⇒ Object
164 165 166 167 |
# File 'lib/vimamsa/util.rb', line 164 def [](x) @a << x return self end |
#val ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/vimamsa/util.rb', line 169 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 |