[EMAIL PROTECTED] wrote:
> Hi,
>
> I would like to access this snippet of code from within my extension
> tags:
>
> class Numeric
> def ordinal
> cardinal = self.to_i.abs
> if (10...20).include?(cardinal) then
> cardinal.to_s << 'th'
> else
> cardinal.to_s << %w{th st nd rd th th th th th th}[cardinal % 10]
> end
> end
> end
>
>
This by itself in a file should be fine. However, if you want to make
sure you're using the existing Numeric class and not creating a new one,
change class Numeric ... end to Numeric.class_eval do ... end.
> As the tags get called on the page I have tried adding the above to:
>
> module StartDate::PageExtensions
> class Numeric < Page
>
> def ordinal
> cardinal = self.to_i.abs
> if (10...20).include?(cardinal) then
> cardinal.to_s << 'th'
> else
> cardinal.to_s << %w{th st nd rd th th th th th th}[cardinal %
> 10]
> end
> end
>
> end
> end
>
>
Here you've made a class StartDate::PageExtensions::Numeric which
inherits from Page. I don't think this is what you want to do. You
want to override the existing Ruby Numeric class.
I would take your first snippet, put it in a file
lib/numeric_extensions.rb, then explicitly require it from your
extension's activate method.
Hope this helps!
Sean
_______________________________________________
Radiant mailing list
Post: [email protected]
Search: http://radiantcms.org/mailing-list/search/
Site: http://lists.radiantcms.org/mailman/listinfo/radiant