Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

AS guide: documents String#singularize

  • Loading branch information...
commit 1064c533ceb46562da39b3b0e50709ceaf0d65d4 1 parent 51e84bf
@fxn fxn authored
Showing with 23 additions and 0 deletions.
  1. +23 −0 railties/guides/source/active_support_core_extensions.textile
View
23 railties/guides/source/active_support_core_extensions.textile
@@ -1276,6 +1276,29 @@ end
NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
+h5. +singularize+
+
+The inverse of +pluralize+:
+
+<ruby>
+"tables".singularize # => "table"
+"rubies".singularize # => "ruby"
+"equipment".singularize # => "equipment"
+</ruby>
+
+Associations compute the name of the corresponding default associated class using this method:
+
+<ruby>
+# active_record/reflection.rb
+def derive_class_name
+ class_name = name.to_s.camelize
+ class_name = class_name.singularize if collection?
+ class_name
+end
+</ruby>
+
+NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
+
h3. Extensions to +Numeric+
h4. Bytes
Please sign in to comment.
Something went wrong with that request. Please try again.