# Re: string range membership

**URL:** <https://www.ruby-forum.com/t/re-string-range-membership/76661>\
**Category:** Ruby\
**Created:** [November 28, 2005, 6:51pm UTC](https://www.ruby-forum.com/t/re-string-range-membership/76661 "2005-11-28T18:51:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![warrenbrown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f9ae1b/32.png) [@warrenbrown](https://www.ruby-forum.com/u/warrenbrown)\
**Post date:** [November 28, 2005, 6:51pm UTC](https://www.ruby-forum.com/t/re-string-range-membership/76661/1 "2005-11-28T18:51:48Z")

</div>

Matz,

> > What about Range#include?? Would it still be an  
> > alias for Range#member?, or would it retain the  
> > current interval check?
> 
> No decided yet. Feel free to say your opinion.

```
Well, I tend to agree with your previous decision on this. Having

```

Enumerable#include? be an alias for Enumerable#member? (or vice-versa),  
but having Range#include? behave differently from Range#member? would be  
confusing. I think it would be better to leave these two methods as  
aliases and add a new method to Range for the interval check. My  
leading candidate for this method is now David A. Black’s suggestion of  
#encompass?. This is a great name and I really like his idea of  
extending it to accept Ranges as parameters so that  
(1…10).encompass?(2…9) == true. Other synonyms could also work:  
#enclose?, #surround?, and even #contain?.

```
- Warren B.
```

---

<div class="post-metadata">

**Author:** ![warrenbrown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f9ae1b/32.png) [@warrenbrown](https://www.ruby-forum.com/u/warrenbrown)\
**Post date:** [November 28, 2005, 7:24pm UTC](https://www.ruby-forum.com/t/re-string-range-membership/76661/2 "2005-11-28T19:24:20Z")

</div>

On Tue, 29 Nov 2005, Warren B. wrote:

> but having Range#include? behave differently from Range#member? would be  
> confusing. I think it would be better to leave these two methods as  
> aliases and add a new method to Range for the interval check. My  
> leading candidate for this method is now David A. Black’s suggestion of  
> #encompass?. This is a great name and I really like his idea of  
> extending it to accept Ranges as parameters so that  
> (1…10).encompass?(2…9) == true. Other synonyms could also work:  
> #enclose?, #surround?, and even #contain?.

reading this just gave me a new idea: first of all, i think this method  
should be a verb so that it implies a loop and test, rather than a  
simply  
test. this is important because the method is, potentally, extremely  
expensive. shortening you suggesting then, how about

(0 … 42).pass? 42 #=\> false  
(0 … 42).pass? 42 #=\> false

for example:

harp:~ \> cat a.rb  
module Enumerable  
#  
# Enumerable#pass? member  
# true if the each method will yield member  
#  
def pass? member  
each{|element| return(element ? element : true) if member ===  
element}  
return nil  
end  
end

p (0 … 42).pass?(42)  
p (0 … 42).pass?(42)  
p [0,1,2,nil].pass?(nil)

open(".bashrc") do |f|  
if ((line = f.pass? %r/screen/))  
puts line  
end  
end

harp:~ \> ruby a.rb  
nil  
42  
true  
alias ss='screen -S ’

thoughts?

-a

---

<div class="post-metadata">

**Author:** ![warrenbrown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f9ae1b/32.png) [@warrenbrown](https://www.ruby-forum.com/u/warrenbrown)\
**Post date:** [November 28, 2005, 8:21pm UTC](https://www.ruby-forum.com/t/re-string-range-membership/76661/3 "2005-11-28T20:21:02Z")

</div>

Hi –

On Tue, 29 Nov 2005, removed\_email\_address@domain.invalid wrote:

> > Well, I tend to agree with your previous decision on this. Having  
> > reading this just gave me a new idea: first of all, i think this method  
> > should be a verb so that it implies a loop and test, rather than a simply  
> > test. this is important because the method is, potentally, extremely  
> > expensive.

“encompass” is a verb 🙂

> shortening you suggesting then, how about
> 
> (0 … 42).pass? 42 #=\> false  
> (0 … 42).pass? 42 #=\> false

I don’t get how “pass” relates to ranges, or enumerables generally.  
Do you mean because it will be “passed” to the block? That seems like  
focusing on the mechanics rather than the semantics of the object.  
(But maybe I’m misunderstanding.)

David

---

<div class="post-metadata">

**Author:** ![warrenbrown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f9ae1b/32.png) [@warrenbrown](https://www.ruby-forum.com/u/warrenbrown)\
**Post date:** [November 28, 2005, 8:12pm UTC](https://www.ruby-forum.com/t/re-string-range-membership/76661/4 "2005-11-28T20:12:53Z")

</div>

removed\_email\_address@domain.invalid wrote:

> (0 … 42).pass? 42 #=\> false  
> (0 … 42).pass? 42 #=\> false

(0…42).pass? 40.5

true or false?

---

<div class="post-metadata">

**Author:** ![warrenbrown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f9ae1b/32.png) [@warrenbrown](https://www.ruby-forum.com/u/warrenbrown)\
**Post date:** [November 29, 2005, 2:48pm UTC](https://www.ruby-forum.com/t/re-string-range-membership/76661/5 "2005-11-29T14:48:23Z")

</div>

removed\_email\_address@domain.invalid wrote:

> reading this just gave me a new idea: first of all, i think this method  
> should be a verb so that it implies a loop and test, rather than a simply  
> test. this is important because the method is, potentally, extremely  
> expensive. shortening you suggesting then, how about

I suggested #generates? elsewhere in the thread, for the same reason - I  
think it important that the method sounds expensive. Are there any  
methods currently in the core/stdlib that sound innocuous but have a  
performance hit under the covers? (#last perhaps?).

martin
