What's the sensible way of saying this.
if @thing == "01" or "02" or "03" or "04" or "05"
(The numbers are contained in a column of datatype string.)
Make an array and use .include?
if ["01","02","03","04","05"].include?(@thing)
If the values really are all consecutive, you can use a range like (1..5).include?
For strings, you can use:
if ("01".."05").include?(@thing)
Or use a case statement:
case @thing
when "01", "02", "03", "04", "05"
# do your things
end
Two variations of this approach:
case @thing
when "01".."05"
# do your things
end
case @thing
when *%w[01 02 03 04 05]
# do your things
end
Because case
uses ===
, you could also write: ("01".."05") === @thing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With