Tbpgr Blog

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

ActiveSupport | String#singularize

概要

String#singularize

詳細

String#singularize について

String#singularize

文字列の単数形を返却する。

サンプル

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

bulk_puts_eval binding, <<-EOS
'heads'.singularize
'bodies'.singularize
'people'.singularize
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

'heads'.singularize # => "head"
'bodies'.singularize # => "body"
'people'.singularize # => "person"