2012-08-16 44 views
3

這是一個奇怪的問題,我不認爲它有答案,但它在這裏。紅寶石寶石用於解決英語中的複數化問題

我在尋找gem這將允許我從複數詞中獲取根詞。

categories => category 
people  => person 
apples  => apple 

招是我需要它在Ruby中,而不是在ROR這樣的解決方案應該從ActiveRecord這可能有這個機制內置的。謝謝你是獨立的。關於這個問題,我還發現http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html/,以防某些人對構建寶石感興趣:)

回答

3

此行爲在ActiveSupport中定義,您可以自行包含此行爲,而不必完全需要Rails。

>> require 'rubygems' 
=> true 
>> require 'active_support/core_ext/string/inflections' 
=> true 
>> "categories".singularize 
=> "category" 
0

您可以要求剛剛從ActiveSupport的語調,而忽略了導軌的其餘部分,像這樣:

require 'active_support/core_ext/string/inflections'

如果不爲你工作,檢查出inflections寶石。

0

您可以隨時安裝active_support gem,只需要變形器,這樣就不會加載所有的rails。軌道的許多部分可以獨立使用。

$ irb 
1.9.3-p194 :001 > require 'active_support/inflector' 
=> true 
1.9.3-p194 :002 > ActiveSupport::Inflector.singularize('inflections') 
=> "inflection"