# Is a "?" at end of method name only for boolean result?

**URL:** <https://www.ruby-forum.com/t/is-a-at-end-of-method-name-only-for-boolean-result/152645>\
**Category:** Ruby\
**Created:** [November 5, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/is-a-at-end-of-method-name-only-for-boolean-result/152645 "2008-11-05T23:45:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 5, 2008, 11:45pm UTC](https://www.ruby-forum.com/t/is-a-at-end-of-method-name-only-for-boolean-result/152645/1 "2008-11-05T23:45:18Z")

</div>

when should I use ? at the end of a method name?. for queries that  
return (a) boolean value, or (b) any return values? ie any method that  
returns data

Thanks

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 6, 2008, 12:35am UTC](https://www.ruby-forum.com/t/is-a-at-end-of-method-name-only-for-boolean-result/152645/2 "2008-11-06T00:35:01Z")

</div>

Greg H. wrote:

> when should I use ? at the end of a method name?. for queries that  
> return (a) boolean value, or (b) any return values? ie any method that  
> returns data
> 
> Thanks

By convention the ? suffix is reserved for methods that return a boolean  
value. Note that all methods return some value, even if it’s just nil.

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 6, 2008, 1:22am UTC](https://www.ruby-forum.com/t/is-a-at-end-of-method-name-only-for-boolean-result/152645/3 "2008-11-06T01:22:23Z")

</div>

Hi,

In message “Re: is a “?” at end of method name only for boolean result?”  
on Thu, 6 Nov 2008 07:42:59 +0900, “Greg H.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|when should I use ? at the end of a method name?. for queries that  
|return (a) boolean value, or (b) any return values? ie any method that  
|returns data

By convention, they are predicates, which means the return value can  
be considered as boolean value. But at the same time, the values are  
not limited to true and false. For example, defined? returns the  
string to describe the kind of expression defined, and nil otherwise.

There’s another convention that when a predicate returns non-true  
value for represent true, it should return nil for false. A bit  
confusing phrase, can you get it?

```
          matz.

```

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 6, 2008, 1:40am UTC](https://www.ruby-forum.com/t/is-a-at-end-of-method-name-only-for-boolean-result/152645/4 "2008-11-06T01:40:30Z")

</div>

On Wed, 05 Nov 2008 18:32:41 -0500, Tim H. wrote:

> Greg H. wrote:
> 
> > when should I use ? at the end of a method name?. for queries that  
> > return (a) boolean value, or (b) any return values? ie any method that  
> > returns data
> > 
> > Thanks
> 
> By convention the ? suffix is reserved for methods that return a boolean  
> value. Note that all methods return some value, even if it’s just nil.

The defined? operater breaks that convention. It returns nil if the name  
it’s given is undefined, but a string indicating what kind of object it  
is if the name is defined. So you could say the ? suffix is intended for  
methods whose outputs are usually treated as boolean.

---

<div class="post-metadata">

**Author:** ![greg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/71c47a/32.png) [@greg](https://www.ruby-forum.com/u/greg)\
**Post date:** [November 7, 2008, 5:41am UTC](https://www.ruby-forum.com/t/is-a-at-end-of-method-name-only-for-boolean-result/152645/5 "2008-11-07T05:41:24Z")

</div>

Greg H. wrote:

> when should I use ? at the end of a method name?. for queries that  
> return (a) boolean value, or (b) any return values? ie any method that  
> returns data
> 
> Thanks

Is the method asking a question or query? By the convention, the method  
should has a question or query (some\_thread.alive? or  
some\_string.empty?) and it should work in an if statement. This is only  
a convention though, but it could be a little confusing if bend the  
rules a little.
