Tbpgr Blog

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

ActiveSupport | String#classify

概要

String#classify

詳細

String#classify について

String#classify

文字列をクラス名形式にする。
tableizeの反対。

サンプル

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

bulk_puts_eval binding, <<-EOS
'human'.classify
'rubies'.classify
'ruby_languages'.classify
'test.ruby_languages'.classify
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

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

出力

'human'.classify # => "Human"
'rubies'.classify # => "Ruby"
'ruby_languages'.classify # => "RubyLanguage"
'test.ruby_languages'.classify # => "RubyLanguage"
'test.ruby_languages'.camelize # => "Test.rubyLanguages"