概要
String#parameterize
詳細
String#parameterize について
String#parameterize
指定文字列に含まれている[a-z0-9\-_]以外の文字を引数sepに置き換えます。
sepを指定しなかった場合は半角ハイフンになります。
サンプル
# encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS 'Module::Class'.parameterize 'Module::Module::Class'.parameterize 'Hoge Hige'.parameterize 'test@at'.parameterize 'test[]unsc'.parameterize 'test@at'.parameterize '=' EOS __END__ ・下記はTbpgrUtils gemの機能 bulk_puts_eval https://rubygems.org/gems/tbpgr_utils https://github.com/tbpgr/tbpgr_utils
出力
'Module::Class'.parameterize # => "module-class" 'Module::Module::Class'.parameterize # => "module-module-class" 'Hoge Hige'.parameterize # => "hoge-hige" 'test@at'.parameterize # => "test-at" 'test[]unsc'.parameterize # => "test-unsc" 'test@at'.parameterize '=' # => "test=at"
参照
http://guides.rubyonrails.org/active_support_core_extensions.html#inflections
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/string/inflections.rb
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/inflections.rb
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflector/transliterate.rb