Hi,
I’d like to implement a guard clause to check whether a value is within a certain range but it gives me a warning: »string literal in condition«:
···
~~~
def billable?(activity)
return false if activity[:project_nbr] == '900'..'999'
# …
true
end
~~~
I’ve looked this up ([1], [2], [3]) and can follow the examples given there and why
~~~
if input == "N" || "n"
~~~
has to be
~~~
if input == "N“ || or input "n"
~~~
But I can’t really get my head around what’s wrong with my above mentioned code.
Anyway, I’ve changed the guard clause to
~~~
return false if activity[:project_nbr] >= '900' and activity[:project_nbr] <= '999'
~~~
and it works, but are there any other approaches to check whether a value is within a certain range and what’s wrong with my first approach?
Many thanks for any ideas on this!
Cheers,
Michael
[1] http://stackoverflow.com/questions/20867709/warning-string-literal-in-condition
[2] http://stackoverflow.com/questions/10896248/ruby-warning-string-literal-in-condition
[3] http://stackoverflow.com/questions/21556673/what-does-string-literal-in-condition-mean