# More loosely typed expression

**URL:** <https://www.ruby-forum.com/t/more-loosely-typed-expression/125297>\
**Category:** Ruby\
**Created:** [January 8, 2008, 1:25am UTC](https://www.ruby-forum.com/t/more-loosely-typed-expression/125297 "2008-01-08T01:25:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@ole](https://www.ruby-forum.com/u/ole)\
**Post date:** [January 8, 2008, 1:25am UTC](https://www.ruby-forum.com/t/more-loosely-typed-expression/125297/1 "2008-01-08T01:25:55Z")

</div>

I’m just trying out RSpec with some really simple code. I have this  
line:

@subject.num(0).fizz?.should == false

And I want it to pass if it’s false OR nil. I tried using =~ but it made  
no difference. Is there no way to do this in Ruby?

---

<div class="post-metadata">

**Author:** ![ole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@ole](https://www.ruby-forum.com/u/ole)\
**Post date:** [January 8, 2008, 4:15am UTC](https://www.ruby-forum.com/t/more-loosely-typed-expression/125297/2 "2008-01-08T04:15:45Z")

</div>

On Jan 7, 2008 7:25 PM, Oliver S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m just trying out RSpec with some really simple code. I have this  
> line:
> 
> @subject.num(0).fizz?.should == false
> 
> And I want it to pass if it’s false OR nil. I tried using =~ but it made  
> no difference. Is there no way to do this in Ruby?

@subject.num(0).fizz?.should be

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![ole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@ole](https://www.ruby-forum.com/u/ole)\
**Post date:** [January 8, 2008, 5:06am UTC](https://www.ruby-forum.com/t/more-loosely-typed-expression/125297/3 "2008-01-08T05:06:03Z")

</div>

On Jan 7, 7:25 pm, Oliver S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m just trying out RSpec with some really simple code. I have this  
> line:
> 
> @subject.num(0).fizz?.should == false
> 
> ## And I want it to pass if it’s false OR nil. I tried using =~ but it made no difference. Is there no way to do this in Ruby?
> 
> Posted viahttp://www.ruby-forum.com/.

This doesn’t exactly answer your question, but isn’t it unusual to  
have a method suffixed with a ? that doesn’t return a boolean value?  
Anyway, here’s a solution:

@subject.num(0).fizz?.should\_not be

Regards,

Jason

---

<div class="post-metadata">

**Author:** ![ole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@ole](https://www.ruby-forum.com/u/ole)\
**Post date:** [January 8, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/more-loosely-typed-expression/125297/4 "2008-01-08T14:20:50Z")

</div>

On Jan 7, 2008 11:05 PM, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Anyway, here’s a solution:
> 
> @subject.num(0).fizz?.should\_not be

Time for me to get new reading glasses, I got the sense of the test  
reversed.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![ole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/fbc32d/32.png) [@ole](https://www.ruby-forum.com/u/ole)\
**Post date:** [January 8, 2008, 5:15am UTC](https://www.ruby-forum.com/t/more-loosely-typed-expression/125297/5 "2008-01-08T05:15:25Z")

</div>

On Jan 7, 11:01 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This doesn’t exactly answer your question, but isn’t it unusual to  
> have a method suffixed with a ? that doesn’t return a boolean value?

Oh yeah, the reason I ask is because, if fizz? acted like other ?  
methods, you could do

@subject.num(0).should\_not be\_fizz

JM
