tags:

views:

38

answers:

3

I don't know if I'm just searching for the wrong things or what, but is there a simple way to evaluate a range and check if an integer is within that range using the (2..100) syntax.

Like just say I wanted to evaluate as true if my integer x = 100, and my range is (2..0), I'm just looking for the simple, concise ruby-way of doing this.

+4  A: 

you can use the member? method of the range to test this

 (1..10).member?(1)   => true
 (1..10).member?(100) => false 
Nikolaus Gradwohl
+3  A: 
(2..100).include?(5) #=> true
(2..100).include?(200) #=> false

Note that 2..0 is an empty range, so (2..0).include?(x) will return false for all values of x.

sepp2k