Forum: Ruby nil.match vs nil.=~

5e7b759194d86939d23a716ad88d92dc?d=identicon&s=25 Kk Kk (sevk)
on 2014-05-08 04:11
a = nil

if a =~ /a/
end

if a.match /a/
  #why error ?
end
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-05-08 21:08
Because match is not defined on NilClass, but =~ is defined on Object,
which is the superclass of NilClass.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.