Created
March 11, 2013 09:33
-
-
Save satoshin2071/5133056 to your computer and use it in GitHub Desktop.
rubyで日付の存在チェック
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.8.7だと | |
[4] pry(main)> Date.exist?(1986, 1, 7) | |
=> 2446438 | |
[5] pry(main)> if Date.exist?(1986, 1, 7) | |
[5] pry(main)* p 'soko' | |
[5] pry(main)* end | |
"soko" | |
=> nil | |
[6] pry(main)> if Date.exist?(1986, 2, 31) | |
[6] pry(main)* p 'soko' | |
[6] pry(main)* end | |
=> nil | |
1.9系使えない? | |
rvm use ruby-1.9.3-p125 | |
[1] pry(main)> Date.exist?(1986, 1, 7) | |
NoMethodError: undefined method `exist?' for Date:Class | |
from (pry):1:in `__pry__' | |
1.9系ではこちら | |
[2] pry(main)> Date.valid_date?(1986,1,7) | |
=> true | |
[3] pry(main)> Date.valid_date?(1986,2,29) | |
=> false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment