So undefined method * for nil:NilClass basically means that the method your calling doesn't exist on the Nil class i.e. a NullReferenceException.
a = nil
a.size
=> undefined method * for nil:NilClass
but if you want to assume a default you can use the || operator to fake out ruby
(nil || "") => ""
a = nil
(a || "").size
=> 0
(!a['href'] || "").index('javascript:')
Sweet huh! :-)
2 comments:
hmm, would be helpful if you gave some context. otherwise i have no idea how to fix this error.
I added some explanation that should help.
Post a Comment