Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

ActiveSupport | ordinalize

概要

ordinalize

詳細

ordinalize について

ordinalize

数値を序数のサフィックス付きのフォーマットにします。

サンプル

# encoding: utf-8
require 'active_support/core_ext/integer/inflections'
require 'tbpgr_utils'

I18n.enforce_available_locales = true
bulk_puts_eval binding, <<-EOS
1.ordinalize
2.ordinalize
3.ordinalize
4.ordinalize
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

1.ordinalize # => "1st"
2.ordinalize # => "2nd"
3.ordinalize # => "3rd"
4.ordinalize # => "4th"