Forum: Ruby another nil concern

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.
9aafe2636a115bbdc137c93445054f22?d=identicon&s=25 Nasir Khan (Guest)
on 2008-12-24 03:44
(Received via mailing list)
irb(main):012:0> nil =~ /foo/
=> false

Should'nt it return nil instead?

BR
nasir
6087a044557d6b59ab52e7dd20f94da8?d=identicon&s=25 Peña, Botp (Guest)
on 2008-12-24 04:15
(Received via mailing list)
From: Nasir Khan [mailto:rubylearner@gmail.com]
# irb(main):012:0> nil =~ /foo/
# => false
#
# Should'nt it return nil instead?

depends on the beholder.

:~$ qri =~
---------------------------- Multiple choices:

     Gem::Dependency#=~, Gem::Platform#=~, Object#=~,
     REXML::Light::Node#=~, RegAnd#=~, RegOr#=~, Regexp#=~, String#=~

:~$ qri object#=~
--------------------------------Object#=~
     obj =~ other  => false
--------------------------------
     Pattern Match---Overridden by descendents (notably Regexp and
     String) to provide meaningful pattern-match semantics.


so you probably want,

> /foo/ =~ nil
=> nil


and if failing is divine, try #match

> /foo/.match nil
=> nil

> nil.match /foo/
NoMethodError: undefined method `match' for nil:NilClass
This topic is locked and can not be replied to.