Abhi Abhi - 1 year ago 77
Ruby Question

Range exclusive of boundaries in ruby

I have a range array like:

range_array = [4830..5520, 2000..2700, 600..1335, 3660..4170]

And I check for range like:

range_array.map{|a| a.include?(3660)}.any? # Gives true as the boundary matches 3660.

I want to check for range excluding boundaries. I tried
, but the problem is same.

How do I achieve it with less code?

Answer Source

You could also check the boundaries using first and last:

range_array.map{|a| a.include?(3660) && a.first != 3660 && a.last != 3660}.any?
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download