# Newbie Question about Array#include?

**URL:** <https://www.ruby-forum.com/t/newbie-question-about-array-include/126633>\
**Category:** Ruby\
**Created:** [January 20, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/newbie-question-about-array-include/126633 "2008-01-20T19:00:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AoP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@AoP](https://www.ruby-forum.com/u/AoP)\
**Post date:** [January 20, 2008, 7:00pm UTC](https://www.ruby-forum.com/t/newbie-question-about-array-include/126633/1 "2008-01-20T19:00:36Z")

</div>

Why does the “include?” method of Array end with a question mark? I  
thought the question mark was to indicate some sort of “unexpected”  
behavior, such as modifying the list, but it doesn’t seem to in this  
case.

Thanks -

-James

---

<div class="post-metadata">

**Author:** ![AoP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@AoP](https://www.ruby-forum.com/u/AoP)\
**Post date:** [January 20, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/newbie-question-about-array-include/126633/2 "2008-01-20T19:05:54Z")

</div>

Alle Sunday 20 January 2008, AoP ha scritto:

> Why does the “include?” method of Array end with a question mark? I  
> thought the question mark was to indicate some sort of “unexpected”  
> behavior, such as modifying the list, but it doesn’t seem to in this  
> case.
> 
> Thanks -
> 
> -James

You’re thinking of the exclamation mark (!), which is used for  
‘dangerous’  
methods or to distinguish methods which modifies the receiver from the  
analogous method wich doesn’t (for example, Array#uniq! and Array#uniq).  
The  
question mark, instead, is used for methods which express a predicate  
or, in  
other words, which answer a question (for example, Array#include?  
answers the  
question ‘does the array contain this item?’)

Stefano

---

<div class="post-metadata">

**Author:** ![AoP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@AoP](https://www.ruby-forum.com/u/AoP)\
**Post date:** [January 20, 2008, 7:14pm UTC](https://www.ruby-forum.com/t/newbie-question-about-array-include/126633/3 "2008-01-20T19:14:42Z")

</div>

AoP wrote:

> Why does the “include?” method of Array end with a question mark? I  
> thought the question mark was to indicate some sort of “unexpected”  
> behavior, such as modifying the list, but it doesn’t seem to in this  
> case.
> 
> Thanks -
> 
> -James

You’re thinking of !, not ?. There are no hard-and-fast rules, but  
typically methods that end in ? return true or false, and methods that  
end in ! need extra attention for one reason or another.

---

<div class="post-metadata">

**Author:** ![AoP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@AoP](https://www.ruby-forum.com/u/AoP)\
**Post date:** [January 21, 2008, 3:23am UTC](https://www.ruby-forum.com/t/newbie-question-about-array-include/126633/4 "2008-01-21T03:23:15Z")

</div>

On Jan 20, 2008, at 12:13 PM, Tim H. wrote:

> that end in ! need extra attention for one reason or another.
> 
> –  
> RMagick: [http://rmagick.rubyforge.org/](http://rmagick.rubyforge.org/)  
> RMagick 2: [http://rmagick.rubyforge.org/rmagick2.html](http://rmagick.rubyforge.org/rmagick2.html)

Also remember that there are some methods in some classes that do not  
have ! but do modify the receiver.  
Array has .push and .pop for examples.

In many languages, equivalents of Ruby methods ending with ? are  
called predicates. They usually read like an English Yes/No or True/  
False question.

---

<div class="post-metadata">

**Author:** ![AoP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71e660/32.png) [@AoP](https://www.ruby-forum.com/u/AoP)\
**Post date:** [January 20, 2008, 7:55pm UTC](https://www.ruby-forum.com/t/newbie-question-about-array-include/126633/5 "2008-01-20T19:55:23Z")

</div>

> question mark, instead, is used for methods which express a predicate or, in  
> other words, which answer a question (for example, Array#include? answers the  
> question ‘does the array contain this item?’)

Thank you!
