require 'active_support/hash_with_indifferent_access'
module Options
  class Registry
    attr_reader :name
    def initialize(name)
      @name = name
      @items = ActiveSupport::HashWithIndifferentAccess.new
    end

    def register(item_name, item)
      if registered?(item_name)
        raise ArgumentError, "#{name} already registered: #{item_name}"
      else
        @items.store(item_name, item)
      end
    end

    def find(item_name)
      if registered?(item_name)
        @items.fetch(item_name)
      else
        raise ArgumentError, "#{name} not registered: #{item_name}"
      end
    end

    def registered?(item_name)
      @items.key?(item_name)
    end
  end
end

require 'active_support/hash_with_indifferent_access'
module Options
  class Registry
    attr_reader :name
    def initialize(name)
      @name = name
      @items = ActiveSupport::HashWithIndifferentAccess.new
    end

    def register(item_name, item)
      if registered?(item_name)
        fail ArgumentError, "#{name} already registered: #{item_name}"
      else
        @items.store(item_name, item)
      end
    end

    def find(item_name)
      if registered?(item_name)
        @items.fetch(item_name)
      else
        fail ArgumentError, "#{name} not registered: #{item_name}"
      end
    end

    def registered?(item_name)
      @items.key?(item_name)
    end
  end
end

Use `fail` instead of `raise` for new errors
Use `fail` instead of `raise` for new errors

Though `fail` and `raise` do exactly the same thing, the style guide[1]
suggests that `raise` be used only to re-raise existing errors in
a `rescue` block and to use `fail` to raise new errors.

[1] https://github.com/bbatsov/ruby-style-guide
