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" 

 

 

 
posted @ 2015-01-08 14:44  wangyuyu  阅读(797)  评论(0编辑  收藏  举报