Integer ordinalization in Ruby/Rails

前端 未结 2 1127
借酒劲吻你
借酒劲吻你 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"
    

提交回复
热议问题