Forum: Ruby on Rails Ordinalizing 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.
7813d26c8ef483e08432ec9c574664d6?d=identicon&s=25 Ben (Guest)
on 2006-05-23 23:47
I'm trying to use the ordinalize() method to ordinalize a day. Here's
how far I've gotten:

@reportday = Time.now.at_beginning_of_week.strftime("%d").to_i
@ordinalized_reportday = "#{@reportday}".ordinalize

I was thinking it wasn't working because the date is being returned as a
string, however I added the .to_i and still it returns an error.

The error I'm getting is:

undefined method `ordinalize' for "22":String

Any ideas?

Thanks.
Ec5a599777854c540fd102ef4691fe10?d=identicon&s=25 Rimantas Liubertas (Guest)
on 2006-05-24 02:06
(Received via mailing list)
2006/5/24, Ben <whywontitletme@yahoo.com>:
> I'm trying to use the ordinalize() method to ordinalize a day. Here's
> how far I've gotten:
>
> @reportday = Time.now.at_beginning_of_week.strftime("%d").to_i
> @ordinalized_reportday = "#{@reportday}".ordinalize
>
> I was thinking it wasn't working because the date is being returned as a
> string, however I added the .to_i and still it returns an error.

Yes, to_i gives you Fixnum, as script/console shows:

>> @reportday = Time.now.at_beginning_of_week.strftime("%d").to_i
=> 22
>> @reportday.class
=> Fixnum

However, you spoil everything with the next lineĆ¢??"#{@reportday}" gives
you a string:

>> "#{@reportday}".class
=> String

You can either do this way: @ordinalized_reportday =
@reportday}.ordinalize,
or all at once:

@ordinalized_reportday =
Time.now.at_beginning_of_week.strftime("%d").to_i.ordinalize

HTH

Regards,
Rimantas
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2006-05-24 03:08
(Received via mailing list)
On 5/23/06, Rimantas Liubertas <rimantas@gmail.com> wrote:
> 2006/5/24, Ben <whywontitletme@yahoo.com>:
> > I'm trying to use the ordinalize() method to ordinalize a day. Here's
> > how far I've gotten:

http://rails.techno-weenie.net/tip/2006/4/2/show_o...
This topic is locked and can not be replied to.