I'm a newbie to Ruby, I have a problem following the Poignant Guide to Ruby:
Does this expression return true?
2005..2009 === 2007
But I don't know why I got this warning message from the following code
wishTraditional.rb:4: warning: integer literal in conditional range
code:
def makTimeLine(year)
if 1984 === year
"Born."
elsif 2005..2009 === year
"Sias."
else
"Sleeping"
end
end
puts makTimeLine(2007)
and the it return Sleeping, which is wrong and should be the Sias
BTW what does the two dots mean? How can I find more information about it?
I think you better use something like that :
elsif (2005..2009).include?(year)
Here is the documentation about Ruby ranges
Update: if you insist on using ===, you should enclose the range in parentheses:
elseif (2005..2009) === year
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