Wondering if anyone can see why I cant call .modulo. I feel like its something like I have to call Math in the class but I Im not sure thats the case.
git: https://github.com/jbasalone/ja/tree/master/ruby/exercism.io/leap
the error:
test_leap_year(YearTest):
NoMethodError: undefined method `modulo' for nil:NilClass
/Users/jennyb/ja/ja/ruby/exercism.io/leap/year.rb:26:in `divbyfour?'
/Users/jennyb/ja/ja/ruby/exercism.io/leap/year.rb:17:in `leap?'
leap_test.rb:6:in `test_leap_year'
This is my code:
class Year
def initialize(theyear)
@theyear = theyear
end
class << self
attr_reader :theyear
def initialize(theyear)
@theyear = theyear
end
def leap?(theyear)
divbyfour? && !acentury? || bcentury?
end
#private
def acentury?
theyear.modulo 100 == 0
end
def divbyfour?
theyear.modulo 4 == 0
end
def bcentury?
theyear.modulo 400 == 0
end
end
end
And this is the test I run against it:
require 'minitest/autorun'
require_relative 'year'
class YearTest < MiniTest::Unit::TestCase
def test_leap_year
assert Year.leap?(1996)
end
def test_non_leap_year
skip
refute Year.leap?(1997)
end
def test_non_leap_even_year
skip
refute Year.leap?(1998)
end
def test_century
skip
refute Year.leap?(1900)
end
def test_fourth_century
skip
assert Year.leap?(2400)
end
end