Created
August 29, 2020 04:43
-
-
Save SyunWatanabe/88c72d2826fb4382c0c25d656a87d03c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Ruby Document | |
| # https://docs.ruby-lang.org/ja/latest/class/Enumerable.html#I_PARTITION | |
| # github: holiday_japan | |
| # https://github.com/masa16/holiday_japan/blob/master/lib/holiday_japan.rb | |
| require 'holiday_japan' | |
| # Enumerable#partitionを使い2020年の祝日がある月を抽出する | |
| year = 2020 | |
| months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] | |
| happy_months, unhappy_months = months.partition do |month| | |
| beginning_day = Date.new(year, month, 1) | |
| end_day = Date.new(year, month, -1) | |
| HolidayJapan.between(beginning_day, end_day).any? | |
| end | |
| puts "We have national holidays on these months in 2020 : #{happy_months})" | |
| puts "We have no national holidays on these months in 2020 : #{unhappy_months})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment