X
Xiangrong Fang
Hi All,
I try to us the following method to prevent some runtime errors:
irb(main):001:0> def NilClass.method_missing(m, *a)
irb(main):002:1> return nil
irb(main):003:1> end
=> nil
irb(main):004:0> a = []
=> []
irb(main):005:0> a[1]
=> nil
irb(main):006:0> a[1].length
NoMethodError: undefined method `length' for nil:NilClass
from (irb):7
You can see that even I let NilClass's method_missing to return nil, it
still report "NoMethodError". I have also tested the following:
irb(main):006:0> a = nil
=> nil
irb(main):007:0> def a.method_missing(m, *a)
irb(main):008:1> return nil
irb(main):009:1> end
=> nil
irb(main):010:0> a.hello
=> nil
This time, it seems worked. Could anyone enlight me please.
Thanks!
Shannon
I try to us the following method to prevent some runtime errors:
irb(main):001:0> def NilClass.method_missing(m, *a)
irb(main):002:1> return nil
irb(main):003:1> end
=> nil
irb(main):004:0> a = []
=> []
irb(main):005:0> a[1]
=> nil
irb(main):006:0> a[1].length
NoMethodError: undefined method `length' for nil:NilClass
from (irb):7
You can see that even I let NilClass's method_missing to return nil, it
still report "NoMethodError". I have also tested the following:
irb(main):006:0> a = nil
=> nil
irb(main):007:0> def a.method_missing(m, *a)
irb(main):008:1> return nil
irb(main):009:1> end
=> nil
irb(main):010:0> a.hello
=> nil
This time, it seems worked. Could anyone enlight me please.
Thanks!
Shannon