# .include?/.within? and English-thinking brains

**URL:** <https://www.ruby-forum.com/t/include-within-and-english-thinking-brains/107748>\
**Category:** Ruby\
**Created:** [June 25, 2007, 10:54pm UTC](https://www.ruby-forum.com/t/include-within-and-english-thinking-brains/107748 "2007-06-25T22:54:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluetrust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@bluetrust](https://www.ruby-forum.com/u/bluetrust)\
**Post date:** [June 25, 2007, 10:54pm UTC](https://www.ruby-forum.com/t/include-within-and-english-thinking-brains/107748/1 "2007-06-25T22:54:45Z")

</div>

In English, it’s clearer to ask, “Is Maggie one of the guests?” –  
rather than the awkward, “Does the guests include Maggie?”

So why in Ruby, do we write, “list.include? scalar” – when we often  
mean, “scalar.within? list” ?!

The solution:

module Comparable  
def within?(list)  
list.include? self  
end  
end

# 

# Examples:

# 

1.within? [1,2,3]

# =\> true

1.within? [2,3]

# =\> false

“arr”.within? “arr, matey”

# =\> true

“arr”.within? “monkey patch”

# =\> false

1.within?( 1 =\> “value” )

# =\> true

1.within?( 2 =\> “value” )

# =\> false

1.within? 1…3

# =\> true

1.within? 2…3

# =\> false

Try it for a morning, your brain will feel better.

---

<div class="post-metadata">

**Author:** ![bluetrust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@bluetrust](https://www.ruby-forum.com/u/bluetrust)\
**Post date:** [June 25, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/include-within-and-english-thinking-brains/107748/2 "2007-06-25T23:18:47Z")

</div>

HI –

On Tue, 26 Jun 2007, Michael J. wrote:

> In English, it’s clearer to ask, “Is Maggie one of the guests?” – rather  
> than the awkward, “Does the guests include Maggie?”

Well, you’re stacking the deck a bit to make it sound awkward (“Does  
the guests”) 🙂 Anyway, we have both; it all depends what you’re  
trying to say.

> So why in Ruby, do we write, “list.include? scalar” – when we often mean,  
> “scalar.within? list” ?!

Because Ruby isn’t English; we use both in English anyway; and Ruby  
doesn’t have #within? 🙂

> The solution:
> 
> module Comparable  
> def within?(list)  
> list.include? self  
> end  
> end

There’s been discussion of this in the past; have a look for #in?  
proposed by Hal a while back.

David
