Permalink
Browse files

AS guide: documents String#singularize

  • Loading branch information...
1 parent 51e84bf commit 1064c533ceb46562da39b3b0e50709ceaf0d65d4 @fxn fxn committed Mar 1, 2010
Showing with 23 additions and 0 deletions.
  1. +23 −0 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

0 comments on commit 1064c53

Please sign in to comment.