ruby中字符的转换

1.将表格名转成class名

  classify

"book_comments".classify
 => "BookComment" 
 

2.class名转成table_name(和上面的相反)
  tableize

"BookComment".tableize
 => "book_comments" 

3.将class名转成class
  constantize

"BookComment".constantize
 => BookComment

4.string复数化(可用于生成table_name)
  pluralize

 "bookcomment".pluralize
 => "bookcomments"

5.string单数化
  singularize

"bookcomments".singularize
 => "bookcomment" 

 

 

 

你可能感兴趣的:(ruby中字符的转换)