Inequality | Interval | Ruby range | Active Record* | Arel** |
---|---|---|---|---|
n >= x | [x..∞) | x.. | where(n: x..) | n.gteq(x) |
n <= x | (-∞..x] | ..x | where(n: ..x) | n.lteq(x) |
n < x | (-∞..x) | ...x | where(n: ...x) | n.lt(x) |
n > x | (x..∞) | n/a | where.not(n: ..x) | n.gt(x) |
x <= n <= y | [x..y] | x..y | where(n: x..y) | n.between(x..y) |
x <= n < y | [x..y) | x...y | where(n: x...y) | n.between(x...y) |
x < n <= y | (x..y] | n/a | where.not(n: ..x).where(n: ..y) | n.gt(x).and(n.lteq(y)) |
x < n < y | (x..y) | n/a | where.not(n: ..x).where(n: ...y) | n.gt(x).and(n.lt(y)) |
* When using predicate builder for Ranges, for reliable scope composition e.g. in the presence of association joins, self-joins, merges etc.
** When n = Model.arel_attribute(:n)
The wheels come off with left-open intervals, for which Ruby has no range literal syntax.