无法使用 ActiveSupport::Inflector 进行复数/单数化(在 irb 中)
irb(main):001:0> require 'active_support'
=> true
irb(main):002:0> require 'active_support/inflector/inflections'
=> true
irb(main):003:0> ActiveSupport::Inflector.pluralize('test')
=> "test"
irb(main):004:0> ActiveSupport::Inflector.singularize('tests')
=> "tests"
irb(main):005:0> ActiveSupport::Inflector.titleize('hat simulator')
=> "Hat Simulator"
<ort::Inflector.tableize("america's number one hat simulator")
=> "america's number one hat simulator"
嗯,基本上,这就是问题所在。让我感到困惑的是,诸如 titleize
之类的方法似乎工作正常,但 tableize
、pluralize
和 singularize
却不起作用。
我忘记要求什么了吗?
(另外,我注意到此页面提供了诸如“post”.pluralize<之类的示例/code>,当我尝试时,导致
NoMethodError: undefined method 'pluralize' for "post":String
但也许这是另一个问题。)
irb(main):001:0> require 'active_support'
=> true
irb(main):002:0> require 'active_support/inflector/inflections'
=> true
irb(main):003:0> ActiveSupport::Inflector.pluralize('test')
=> "test"
irb(main):004:0> ActiveSupport::Inflector.singularize('tests')
=> "tests"
irb(main):005:0> ActiveSupport::Inflector.titleize('hat simulator')
=> "Hat Simulator"
<ort::Inflector.tableize("america's number one hat simulator")
=> "america's number one hat simulator"
Well, basically, that's the question. It's confusing me that methods such as titleize
seem to work fine, but tableize
, pluralize
and singularize
don't.
Have I forgotten to require something?
(On a separate note, I notice this page provides examples like "post".pluralize
, which when I tried, resulted in NoMethodError: undefined method 'pluralize' for "post":String
. But maybe that's something to save for another question.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无需向
String
类添加新方法即可访问#pluralize
:对于
String
类:实际调用
ActiveSupport::Inflector.pluralize
下面:Access to
#pluralize
without adding new methods to theString
class:For
String
class:which actually calls
ActiveSupport::Inflector.pluralize
underneath: