# How to use select

**URL:** <https://www.ruby-forum.com/t/how-to-use-select/192394>\
**Category:** Ruby\
**Created:** [July 29, 2010, 3:29pm UTC](https://www.ruby-forum.com/t/how-to-use-select/192394 "2010-07-29T15:29:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arachnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@arachnd](https://www.ruby-forum.com/u/arachnd)\
**Post date:** [July 29, 2010, 3:29pm UTC](https://www.ruby-forum.com/t/how-to-use-select/192394/1 "2010-07-29T15:29:55Z")

</div>

Hello people I have been looking around but i have not been able to run  
a succesful select it always failed on me.

i also dont understand if there is a diference between IO.select or just  
select()

Could you be so kind to let me know how it works?

---

<div class="post-metadata">

**Author:** ![arachnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@arachnd](https://www.ruby-forum.com/u/arachnd)\
**Post date:** [July 29, 2010, 5:34pm UTC](https://www.ruby-forum.com/t/how-to-use-select/192394/2 "2010-07-29T17:34:19Z")

</div>

Daniel Flores wrote:

> Hello people I have been looking around but i have not been able to run  
> a succesful select it always failed on me.
> 
> i also dont understand if there is a diference between IO.select or just  
> select()

They are different 🙂

> Could you be so kind to let me know how it works?

Array.select:

- [class Array - RDoc Documentation](http://ruby-doc.org/core/classes/Array.html#M002191)

1. arr = [“one”, “two”, “three”, “four”]  
=\> [“one”, “two”, “three”, “four”]
2. arr.select{ |s| s == “two” }  
=\> [“two”]
3. arr.map{ |s| s == “two” }  
=\> [false, true, false, false]

IO.select:  
\*  
[http://ruby-doc.org/docs/ProgrammingRuby/html/ref\_m\_kernel.html#Kernel.select](http://ruby-doc.org/docs/ProgrammingRuby/html/ref_m_kernel.html#Kernel.select)

- [module Kernel - RDoc Documentation](http://ruby-doc.org/core/classes/Kernel.html#M005958)

“Performs a low-level select call, which waits for data to become  
available from input/output  
devices. The first three parameters are arrays of IO objects or nil. The  
last is a timeout in  
seconds, which should be an Integer or a Float. The call waits for data  
to become available for  
any of the IO objects in readArray, for buffers to have cleared  
sufficiently to enable writing  
to any of the devices in writeArray, or for an error to occur on the  
devices in errorArray. If  
one or more of these conditions are met, the call returns a  
three-element array containing  
arrays of the IO objects that were ready. Otherwise, if there is no  
change in status for  
timeout seconds, the call returns nil. If all parameters are nil, the  
current thread sleeps”

forever.select( [$stdin], nil, nil, 1.5 ) Â» [[#IO:0x401ba090], [],  
[]]

Read the links they will be useful to you.

~jbw

---

<div class="post-metadata">

**Author:** ![arachnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@arachnd](https://www.ruby-forum.com/u/arachnd)\
**Post date:** [July 29, 2010, 11:43pm UTC](https://www.ruby-forum.com/t/how-to-use-select/192394/3 "2010-07-29T23:43:26Z")

</div>

Jason W. wrote:

> Jason W. wrote:
> 
> > Daniel Flores wrote:
> > 
> > > Hello people I have been looking around but i have not been able to run  
> > > a succesful select it always failed on me.
> > > 
> > > i also dont understand if there is a diference between IO.select or just  
> > > select()
> 
> I’m assuming the other select your talking about is Array.select… if  
> not say which.

IIUC, Kernel#select is the same as IO.select. I avoid using the former,  
just to be explicit, in case self happens to have a select method (self  
is a collection of some kind, for example).

---

<div class="post-metadata">

**Author:** ![arachnd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/278dde/32.png) [@arachnd](https://www.ruby-forum.com/u/arachnd)\
**Post date:** [July 29, 2010, 5:37pm UTC](https://www.ruby-forum.com/t/how-to-use-select/192394/4 "2010-07-29T17:37:10Z")

</div>

Jason W. wrote:

> Daniel Flores wrote:
> 
> > Hello people I have been looking around but i have not been able to run  
> > a succesful select it always failed on me.
> > 
> > i also dont understand if there is a diference between IO.select or just  
> > select()

I’m assuming the other select your talking about is Array.select… if  
not say which.

> They are different 🙂
> 
> > Could you be so kind to let me know how it works?
