我正在寻找将单个单词转换为模型内不定式的方法:
cats -> cat
sharpest -> sharp
etc.
你知道任何能够做到这一点的宝石或图书馆吗?
答案 0 :(得分:1)
String#singularize提供:复数的反转,返回字符串中单词的单数形式。
'posts'.singularize # => "post"
'octopi'.singularize # => "octopus"
'sheep'.singularize # => "sheep"
'word'.singularize # => "word"
'the blue mailmen'.singularize # => "the blue mailman"
'CamelOctopi'.singularize # => "CamelOctopus"
'leyes'.singularize(:es) # => "ley"
for String#pluralize:返回字符串中复数形式的单词。
'post'.pluralize # => "posts"
'octopus'.pluralize # => "octopi"
'sheep'.pluralize # => "sheep"
'words'.pluralize # => "words"
'the blue mailman'.pluralize # => "the blue mailmen"
'CamelOctopus'.pluralize # => "CamelOctopi"
'apple'.pluralize(1) # => "apple"
'apple'.pluralize(2) # => "apples"
'ley'.pluralize(:es) # => "leyes"
'ley'.pluralize(1, :es) # => "ley"
此外,您还可以查看'verbs' gem
为所有人,时态,标准共轭最常见的英语动词 方面和现代情绪(具有主动素质)。标准和 遵守特殊的拼写规则。