Determining if a variable is within range? Determining if a variable is within range? ruby ruby

Determining if a variable is within range?


if i.between?(1, 10)  do thing 1 elsif i.between?(11,20)  do thing 2 ...


Use the === operator (or its synonym include?)

if (1..10) === i


As @Baldu said, use the === operator or use case/when which internally uses === :

case iwhen 1..10  # do thing 1when 11..20  # do thing 2when 21..30  # do thing 3etc...