Rails "ta".classify 的结果是什么?

ichord · December 21, 2012 · Last by darkbaby123 replied at January 17, 2013 · 3056 hits

如题,今天在 Rails 碰到个奇怪的问题

"ta".classify

输出的结果会是什么?! 如果知道为什么的同学顺便回答了吧!

$ pry
> require 'active_support/all'
> cd String
> show-doc classify

classify 没什么关系。具体请查 singularize 的 inflection 规则。

#1 楼 @luikore what is the pry used to do ?

#3 楼 @zhangxun 把 pry 脑补成 irb 即可

Rails API 的例子,注意复数词 classify 后会变单数。就是说 Rails 那个单复数转换的规则会影响这个

"egg_and_hams".classify # => "EggAndHam"
"posts".classify        # => "Post"

实际上我觉得这货就是用来把 table 名字变类名的。Rails API 原文解释 Create a class name from a plural table name like Rails does for table names to models.

You need to Sign in before reply, if you don't have an account, please Sign up first.