Last Updated: February 25, 2016
·
545
· roxasshadow

Chained expressions

Have you ever wanted to do a thing like the following in ruby?

a < b < c < d

Contrary to languages as python and perl6, ruby hasn't a native support to chained expressions, but you can implement them through a gem.

Install

$ gem install chainedexpressions

Example

require 'chainedexpressions'
using ChainedExpressions

20 < 25
20 < 25 < 30

20 <= 25 <= 30 <= 30 <= 35

35 > 30 > 25  > 20
20 >  3 > 2.2 > -2

35 >= 30 >= 30 >= 25 >= 20