Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat exactly does this Rails module do, and how does it work?
    primarykey
    data
    text
    <p>I am fairly new to Ruby and I fail to see the connection between all those classes and methods. Could you please explain a little what exactly each method does:</p> <pre><code>module Naming # Returns an ActiveModel::Name object for module. It can be # used to retrieve all kinds of naming-related information. def model_name @_model_name ||= begin namespace = self.parents.detect do |n| n.respond_to?(:use_relative_model_naming?) &amp;&amp; n.use_relativve_model_naming? end ActiveModel::Name.new(self, namespace) end end # Returns the plural class name of a record or class. Examples: # # ActiveModel::Naming.plural(post) # =&gt; "posts" # ActiveModel::Naming.plural(Highrise::Person) # =&gt; "highrise_people" def self.plural(record_or_class) model_name_from_record_or_class(record_or_class).plural end # Returns the singular class name of a record or class. Examples: # # ActiveModel::Naming.singular(post) # =&gt; "post" # ActiveModel::Naming.singular(Highrise::Person) # =&gt; "highrise_person" def self.singular(record_or_class) model_name_from_record_or_class(record_or_class).singular end # Identifies whether the class name of a record or class is uncountable. Examples: # # ActiveModel::Naming.uncountable?(Sheep) # =&gt; true # ActiveModel::Naming.uncountable?(Post) =&gt; false def self.uncountable?(record_or_class) plural(record_or_class) == singular(record_or_class) end # Returns string to use while generating route names. It differs for # namespaced models regarding whether it's inside isolated engine. # # For isolated engine: # ActiveModel::Naming.route_key(Blog::Post) #=&gt; post # # For shared engine: # ActiveModel::Naming.route_key(Blog::Post) #=&gt; blog_post def self.singular_route_key(record_or_class) model_name_from_record_or_class(record_or_class).singular_route_key end # Returns string to use while generating route names. It differs for # namespaced models regarding whether it's inside isolated engine. # # For isolated engine: # ActiveModel::Naming.route_key(Blog::Post) #=&gt; posts # # For shared engine: # ActiveModel::Naming.route_key(Blog::Post) #=&gt; blog_posts # # The route key also considers if the noun is uncountable and, in # such cases, automatically appends _index. def self.route_key(record_or_class) model_name_from_record_or_class(record_or_class).route_key end # Returns string to use for params names. It differs for # namespaced models regarding whether it's inside isolated engine. # # For isolated engine: # ActiveModel::Naming.param_key(Blog::Post) #=&gt; post # # For shared engine: # ActiveModel::Naming.param_key(Blog::Post) #=&gt; blog_post def self.param_key(record_or_class) model_name_from_record_or_class(record_or_class).param_key end private def self.model_name_from_record_or_class(record_or_class) (record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name end def self.convert_to_model(object) object.respond_to?(:to_model) ? object.to_model : object end end end </code></pre> <p>I know there are comments for each method but I still fail to understand basic meta.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload