Module: Kernel

Defined in:
lib/monthify/month.rb

Instance Method Summary collapse

Instance Method Details

#Month(object_to_convert) ⇒ Month

Globally accessible method to convert an argument into a Month. If the argument cannot be converted, it raises an ArgumentError

Parameters:

  • object_to_convert (Month, #to_date)

    the object to convert to a Month

Returns:

  • (Month)

    the given Month or the Month containing the given date



143
144
145
146
147
148
149
150
151
# File 'lib/monthify/month.rb', line 143

def Month(object_to_convert)
  if object_to_convert.is_a?(Month)
    object_to_convert
  elsif object_to_convert.respond_to?(:to_date)
    Month.containing(object_to_convert.to_date)
  else
    raise ArgumentError, "Don't know how to convert #{object_to_convert.inspect} to Month"
  end
end