@marksiemers1/LeapYearOverloads
Ruby

No description

fork
loading
repl talk
(games)
Files
  • main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require "date"

module Year
  def self.leap?(input)
    if input.is_a? Integer 
      input % 400 == 0 || (input % 100 != 0 && input % 4 == 0)
    elsif input.is_a? Date
      input.leap?
    else
      raise ArgumentError.new("must pass an Integer or Date.")
    end
  end
end

puts Year.leap?(2016)
puts Year.leap?(Date.new(2016,1,1))
puts Year.leap?("2016")
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]