[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

another nil concern

Nasir Khan

12/24/2008 2:34:00 AM

[Note: parts of this message were removed to make it a legal post.]

irb(main):012:0> nil =~ /foo/
=> false

Should'nt it return nil instead?

BR
nasir

1 Answer

Peña, Botp

12/24/2008 3:06:00 AM

0

From: Nasir Khan [mailto:rubylearner@gmail.com]=20
# irb(main):012:0> nil =3D~ /foo/
# =3D> false
#=20
# Should'nt it return nil instead?

depends on the beholder.

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

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

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


so you probably want,

> /foo/ =3D~ nil
=3D> nil


and if failing is divine, try #match

> /foo/.match nil
=3D> nil

> nil.match /foo/
NoMethodError: undefined method `match' for nil:NilClass