I’m trying to implement dehumanize method in Rails 3. Basically what
this post does:
Here:
module ActiveSupport::Inflector
does the opposite of humanize… mostly. Basically does a
space-substituting .underscore
def dehumanize(the_string)
result = the_string.to_s.dup
result.downcase.gsub(/ +/,‘_’)
end
end
class String
def dehumanize
ActiveSupport::Inflector.dehumanize(self)
end
end
config/inflections.rb in Rails 3 says:
Add new inflection rules using the following format
ActiveSupport::Inflector.inflections do |inflect|
inflect.plural /^(ox)$/i, ‘\1en’
end