new(klass, namespace = nil, name = nil) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activemodel/lib/active_model/naming.rb, line 15
    def initialize(klass, namespace = nil, name = nil)
      name ||= klass.name

      raise ArgumentError, "Class name cannot be blank. You need to supply a name argument when anonymous class given" if name.blank?


      @unnamespaced = self.sub(/^#{namespace.name}::/, '') if namespace
      @klass        = klass
      @singular     = _singularize(self).freeze
      @plural       = ActiveSupport::Inflector.pluralize(@singular).freeze
      @element      = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze
      @human        = ActiveSupport::Inflector.humanize(@element).freeze
      @collection   = ActiveSupport::Inflector.tableize(self).freeze
      @partial_path = "#{@collection}/#{@element}".freeze
      @param_key    = (namespace ? _singularize(@unnamespaced) : @singular).freeze
      @i18n_key     = self.underscore.to_sym

      @route_key          = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural.dup)
      @singular_route_key = ActiveSupport::Inflector.singularize(@route_key).freeze
      @route_key << "_index" if @plural == @singular
Register or log in to add new notes.