dry-inflector Join the chat at https://gitter.im/dry-rb/chat

Gem Version Build Status Dependency Status Code Climate Test Coverage Inline docs

dry-inflector is an inflector gem for Ruby.


Add this line to your application's Gemfile:

gem 'dry-inflector'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dry-inflector


Basic usage

require "dry/inflector"

inflector = Dry::Inflector.new

inflector.pluralize("book")    # => "books"
inflector.singularize("books") # => "book"

inflector.camelize("dry/inflector") # => "Dry::Inflector"
inflector.classify("books")         # => "Book"
inflector.tableize("Book")          # => "books"

inflector.dasherize("dry_inflector")  # => "dry-inflector"
inflector.underscore("dry-inflector") # => "dry_inflector"

inflector.demodulize("Dry::Inflector") # => "Inflector"

inflector.humanize("dry_inflector")    # => "Dry inflector"
inflector.humanize("author_id")        # => "Author"

inflector.ordinalize(1)  # => "1st"
inflector.ordinalize(2)  # => "2nd"
inflector.ordinalize(3)  # => "3rd"
inflector.ordinalize(10) # => "10th"
inflector.ordinalize(23) # => "23rd"

Custom inflection rules

require "dry/inflector"

inflector = Dry::Inflector.new do |inflections|
  inflections.plural      "virus",   "viruses" # specify a rule for #pluralize
  inflections.singular    "thieves", "thief"   # specify a rule for #singularize
  inflections.uncountable "dry-inflector"      # add an exception for an uncountable word

inflector.pluralize("virus")     # => "viruses"
inflector.singularize("thieves") # => "thief"

inflector.pluralize("dry-inflector") # => "dry-inflector"


This gem is the cumulative effort of the Ruby community. It started with the extlib inflecto originated from active_support, then dm-core inflector originated from extlib. Later, inflecto was extracted from dm-core as a standalone inflector. Now, we resurrect inflecto and merged flexus, with some inflection rules from hanami-utils.

This is dry-inflector.


After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.


Bug reports and pull requests are welcome on GitHub at https://github.com/dry-rb/dry-inflector.

Copyright © The Dry, Rails, Merb, Datamapper, Inflecto, Flexus, and Hanami teams - Released under the MIT License