Is there an easy way to determine if a year is a leap year?
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- gem cleanup shows error: Unable to uninstall bundl
相关文章
- Ruby using wrong version of openssl
- How to truncate seconds in TSQL?
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- How to remove seconds from datetime?
- Segmentation fault with ruby 2.0.0p247 leading to
- OLS with pandas: datetime index as predictor
The variable n takes year to test and prints true if it's a leap year and false if it's not.
This one takes a range:
Source: Learn to Program by Chris Pine
Using the least amount possible of comparisons, you could do this:
We can do the same check using short circuit OR (
||
):Try this:
Use
Date#leap?
.e.g.