# Dry::Inflector future api

**URL:** <https://discourse.dry-rb.org/t/dry-inflector-future-api/398>\
**Category:** Ideas\
**Created:** [November 16, 2017, 11:41am UTC](https://discourse.dry-rb.org/t/dry-inflector-future-api/398 "2017-11-16T11:41:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abinoam](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/abinoam/32/35_2.png) [@abinoam](https://discourse.dry-rb.org/u/abinoam)\
**Post date:** [November 16, 2017, 11:41am UTC](https://discourse.dry-rb.org/t/dry-inflector-future-api/398/1 "2017-11-16T11:41:41Z")

</div>

Basically we want to provide the simplest and more straightforward api for the more common case.

```ruby
inflector = Dry::Inflector.new
inflector.pluralize("book")

```

While giving room for customizations over this simplest case.

```ruby
inflector = Dry::Inflector.new do |inflections|
  inflections.plural "libro", "libri" # Italian words for "book" and "books"
end

inflector.pluralize("libro") #=> libri

```

For more complex cases we could use a full blown `Inflections` object like:

```ruby
italian = Dry::Inflector::Inflections.new do |inflections|
  inflections.plural "libro", "libri"
end

inflector = Dry::Inflector.new(inflections: italian)
inflector.pluralize("libro")

```

This way, we could provide a built-in set of inflections rules aimed at compatibility with other libraries like:

```auto
Dry::Inflector::Inflections::ActiveSupport =
  Dry::Inflector::Inflections.new do |inflections|
    inflections.plural "person", "people"
  end

as_compatible_inflector = Dry::Inflector.new(inflections: Dry::Inflector::Inflections::ActiveSupport)
as_compatible_inflector.pluralize("people") # => "people"

```

This discussion began at [https://github.com/dry-rb/dry-inflector/issues/9](https://github.com/dry-rb/dry-inflector/issues/9)

---

<div class="post-metadata">

**Author:** ![abinoam](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/abinoam/32/35_2.png) [@abinoam](https://discourse.dry-rb.org/u/abinoam)\
**Post date:** [November 16, 2017, 12:21pm UTC](https://discourse.dry-rb.org/t/dry-inflector-future-api/398/2 "2017-11-16T12:21:45Z")

</div>

One thing I’m still not sure how to accomplish is composition of inflection rules.

Take the ActiveSupport inflections example:

```ruby
Dry::Inflector::Inflections::ActiveSupport =
  Dry::Inflector::Inflections.new do |inflections|
    inflections.plural "person", "people"
  end

as_compatible_inflector = Dry::Inflector.new(inflections: Dry::Inflector::Inflections::ActiveSupport)
as_compatible_inflector.pluralize("people") # => "people"

```

How can I add my own inflection rules on top of the given `Dry::Inflector::Inflections::ActiveSupport`?  
For the simplest case, just providing a block will be enough.  
But if I want to stack 2 or 3 different rulesets that I don’t have direct access to their code?  
For example `Dry::Inflector::Inflections::Italian` and `Dry::Inflector::Inflections::ActiveSupportCompatible` ?

Please let me know if I’m not being clear about it.

By the way, If we define a good way to accomplish this we will also solve internationalization in a roll.

cc: @jodosha @solnic @Ptico

---

<div class="post-metadata">

**Author:** ![Ptico](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/ptico/32/168_2.png) [@Ptico](https://discourse.dry-rb.org/u/Ptico)\
**Post date:** [November 16, 2017, 2:40pm UTC](https://discourse.dry-rb.org/t/dry-inflector-future-api/398/3 "2017-11-16T14:40:49Z")

</div>

I see two ways for composing rules:

1. Rules inheritance:

```ruby
Italian = Dry::Inflector::Inflections.new(ActiveSupportCompatible) do
# ...
end

```

1. Composition:

```ruby
Dry::Inflector.new([ActiveSupportCompatible, Italian])

```

Composition will basically create a new ruleset and copy all rules from given rulesets, so I think we will also need to create some interface for precomposing (and receive something like variant #1)

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.dry-rb.org/solnic/32/779_2.png) [@solnic](https://discourse.dry-rb.org/u/solnic)\
**Post date:** [November 23, 2017, 8:32am UTC](https://discourse.dry-rb.org/t/dry-inflector-future-api/398/4 "2017-11-23T08:32:06Z")

</div>

It’d be nice if we could only expose `Dry::Inflector` in the public API. So maybe having two methods for buiding up rules + inflector? `Dry::Inflector.new { ... }` and `Dry::Inflector.rules { .. }`? Also, passing rules to the `.new` method sounds like a good idea.
