Integer ordinalization in Ruby/Rails

前端 未结 2 1122
借酒劲吻你
借酒劲吻你 2021-02-20 02:08

I\'m looking for a way to handle integer ordinalization in Ruby/Rails, ie. \"st\", \"nd\", \"rd\", and \"th\" suffixes to integers. Ruby on Rails used to extend FixNum with an \

相关标签:
2条回答
  • 2021-02-20 02:19

    The method you want is still ordinalize.

    Active_Support was refactored a bit to provide better granularity. Instead of loading in everything at once, you can select smaller chunks depending on what you need.

    You can either load everything in Active_Support using require 'active_support/all', or break it down using require 'active_support/core_ext/integer/inflections':

    >> require 'active_support/core_ext/integer/inflections' #=> true
    >> 1.ordinalize #=> "1st"
    
    0 讨论(0)
  • 2021-02-20 02:20

    Lately (last I knew) there has been a trend to not modify core classes. The Rails-Core mailing list might have a better answer for this one.

    It looks like that functionality was moved to Inflector from a Fixnum extension which makes sense. Hopefully someone else can confirm this.

    0 讨论(0)
提交回复
热议问题