Ordinalizing a date


#1

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.


#2

2006/5/24, Ben removed_email_address@domain.invalid:

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


#3

On 5/23/06, Rimantas L. removed_email_address@domain.invalid wrote:

2006/5/24, Ben removed_email_address@domain.invalid:

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_ordinalized_days_when_formatting_times