# Another nil concern

**URL:** <https://www.ruby-forum.com/t/another-nil-concern/156296>\
**Category:** Ruby\
**Created:** [December 24, 2008, 3:44am UTC](https://www.ruby-forum.com/t/another-nil-concern/156296 "2008-12-24T03:44:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [December 24, 2008, 3:44am UTC](https://www.ruby-forum.com/t/another-nil-concern/156296/1 "2008-12-24T03:44:39Z")

</div>

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

Should’nt it return nil instead?

BR  
nasir

---

<div class="post-metadata">

**Author:** ![Nasir\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/838e76/32.png) [@Nasir\_K](https://www.ruby-forum.com/u/Nasir_K)\
**Post date:** [December 24, 2008, 4:15am UTC](https://www.ruby-forum.com/t/another-nil-concern/156296/2 "2008-12-24T04:15:40Z")

</div>

From: Nasir K. [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

# 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
