读取web
instance_variable_get("@name") #返回@name值
设置ruby
instance_variable_set("@name", "三国演义") #@name = "三国演义"
method相关 string到method名 sendbash
book.send("name") #返回 book.name值
注意: book.send(“name”) = “三国演义” 会出错. svg
但能够:post
book.send("name=", "三国演义") #book.name = "三国演义"
单复数转化 string复数化 pluralize 可用于生成table_nameui
"country".pluralize #=> "countries"
string单数化 singularize 和上面的相反spa
"posts".singularize #=> "post"
table和class相关 将表格名转成class名 classifycode
"blog_pictures".classify #=> "BlogPicture"
转成table_name(和上面的相反) tableizeserver
"BlogPicture".tableize #=> "blog_pictures"
将class名转成class constantizexml
"Country".constantize #=> Country
能够将classify和constantize联用将string转成class model
"books".classify.constantize.find_by_name("三国演义")
#=> Book.find_by_name("三国演义")