How to convert 1 to “first”, 2 to “second”, and so on, in Ruby?

后端 未结 4 1282
慢半拍i
慢半拍i 2021-01-17 07:26

Is there a built-in method in Ruby to support this?

4条回答
  •  梦毁少年i
    2021-01-17 08:12

    Using humanize gem, is probably the easiest way. But, yes, it is not built in, however it has only one dependency, so I think its a pretty good choice..

    require 'humanize'
    
    2.humanize  => "two"
    

提交回复
热议问题