Why is this not working?
case ARGV.length when 0 abort "Error 1" when > 2 abort "Error 2" end
You can't use “||” in case names.
Ruby uses the case for writing switch statements.
Case statement in the Ruby is a way to execute different codes and expressions on the basis of the values provided to the case, case statement in Ruby is similar to basic switch cases in the other programming languages.
It's not valid ruby syntax.
What you need is
case when ARGV.length == 0 abort "Error 1" when ARGV.length > 2 abort "Error 2" end
When you write case x
, the important part you need to understand is that ruby takes the x and then applies a comparison to the argument or expressions you insert in the when
clause.
The line where you say when x >2
reads to ruby like:
if ARGV.length == > 2
When you remove a specific object from the case
statements, you can apply conditionals within the when
statements .
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