holidays / holidays

A collection of Ruby methods to deal with statutory and other holidays. You deserve a holiday!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NoMethodError: undefined method `holiday?'

itsecureadmin opened this issue · comments

It seems the holiday? method is broken in version 3.0.0 (although I have not tested any other versions):

gem install holidays
Fetching: holidays-3.0.0.gem (100%)
Successfully installed holidays-3.0.0
Parsing documentation for holidays-3.0.0
Installing ri documentation for holidays-3.0.0
Done installing documentation for holidays after 1 seconds
1 gem installed

irb -rpp
2.2.0 :001 > require 'holidays'
=> true
2.2.0 :002 > require 'generated_definitions/us'
=> true
2.2.0 :003 > Date.today.holiday?
NoMethodError: undefined method holiday?' for #<Date: 2015-12-16 ((2457373j,0s,0n),+0s,2299161j)> from (irb):3 from /Users/user/.rvm/rubies/ruby-2.2.0/bin/irb:11:in

'
2.2.0 :004 > require 'holidays/core_extensions/date'
=> true
2.2.0 :005 > Date.today.holiday?
NoMethodError: undefined method holiday?' for #<Date: 2015-12-16 ((2457373j,0s,0n),+0s,2299161j)> from (irb):5 from /Users/user/.rvm/rubies/ruby-2.2.0/bin/irb:11:in'
2.2.0 :006 > Date.today.holiday?(:us)
NoMethodError: undefined method holiday?' for #<Date: 2015-12-16 ((2457373j,0s,0n),+0s,2299161j)> from (irb):6 from /Users/user/.rvm/rubies/ruby-2.2.0/bin/irb:11:in'
2.2.0 :007 >

Thanks for the report! Long story short: we are not auto-monkey-patching the Date class anymore. We require that you manually load the core extension, like so:

require 'holidays/core_extensions/date'
class Date
  include Holidays::CoreExtensions::Date
end

I changed the section on how to use it in the README: https://github.com/holidays/holidays#extending-rubys-date-class

I'm no expert when it comes to core extensions but based on feedback I received previously this was the accepted way to do it. If you use this in a project then you can just make sure the code snippet above is loaded when you app/project starts and you'll have the additional method.

Additional feedback welcome!

That was it, thanks. I had seen that but it was not abundantly clear to me as I am no expert in this area either.