Forum: Ruby nil.match vs nil.=~

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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.
This topic is locked and can not be replied to.