gpt4 book ai didi

ruby-on-rails - 序数 : '1' as '1st' , '2' 为 '2nd' 等的 Ruby 格式

转载 作者:数据小太阳 更新时间:2023-10-29 06:29:10 26 4
gpt4 key购买 nike

ruby 或 rails 中是否有任何东西可以处理序数的格式:'1' 为 '1st','2' 为 '2nd',等等?

最佳答案

看起来你正在寻找序号:

The Ruby on Rails framework is chock full of interesting little nuggets. Ordinalize is a number extension that returns the corresponding ordinal number as a string. For instance, 1.ordinalize returns “1st” and 22.ordinalize return “22nd”.

Example:

place = 3puts "You are currently in #{place.ordinalize} place."

Result:

You are currently in 3rd place.

关于ruby-on-rails - 序数 : '1' as '1st' , '2' 为 '2nd' 等的 Ruby 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3311415/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com