Forum: Ruby Dumb question - how to get day/month names from a date?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Adam B. (Guest)
on 2006-05-06 22:18
I can't for the life of me figure this one out. I know that the Date
class has constants including MONTHNAMES and DAYNAMES, but I have no
idea how to access them.

day = Date.today
Date.constants

>["MONTHS", "ABBR_DAYS", "DAYNAMES", "ENGLAND", "DATE_FORMATS", "PARSE_DAYPAT", 
"ABBR_MONTHNAMES", "ABBR_MONTHS", "ITALY", "PARSE_MONTHPAT", "MONTHNAMES", "GREGORIAN", 
"DAYS", "ZONES", "ABBR_DAYNAMES", "JULIAN"]

day.italy
>#<Date: 4907723/2,0,2299161>

day.monthnames
> NoMethodError: undefined method `monthnames' for #<Date: 4907723/2,0,2299161>

How do I access that constant?

-Adam
Leslie V. (Guest)
on 2006-05-06 22:30
(Received via mailing list)
On 5/6/06, Adam B. <removed_email_address@domain.invalid> wrote:
> >#<Date: 4907723/2,0,2299161>
>
> day.monthnames
> > NoMethodError: undefined method `monthnames' for #<Date: 4907723/2,0,2299161>

Date::MONTHNAMES

It's a constant in the Date class. You use "::" to get at constants,
"." to get at methods.

Les
This topic is locked and can not be replied to.