Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4654

Show
Ignore:
Timestamp:
08/03/06 21:29:07 (2 years ago)
Author:
bitsweat
Message:

Thoroughly document inflections. Closes #5700.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r4653 r4654  
    11*SVN* 
     2 
     3* Thoroughly document inflections.  #5700 [petermichaux@gmail.com] 
    24 
    35* Added Module#alias_attribute [Jamis/DHH]. Example: 
  • trunk/activesupport/lib/active_support/core_ext/string/inflections.rb

    r4453 r4654  
    1212        # Examples 
    1313        #   "post".pluralize #=> "posts" 
     14        #   "octopus".pluralize #=> "octopi" 
    1415        #   "sheep".pluralize #=> "sheep" 
     16        #   "words".pluralize #=> "words" 
    1517        #   "the blue mailman".pluralize #=> "the blue mailmen" 
     18        #   "CamelOctopus".pluralize #=> "CamelOctopi" 
    1619        def pluralize 
    1720          Inflector.pluralize(self) 
     
    2124        # 
    2225        # Examples 
    23         #   "posts".singularize => "post" 
    24         #   "the blue mailmen".pluralize #=> "the blue mailman" 
     26        #   "posts".singularize #=> "post" 
     27        #   "octopi".singularize #=> "octopus" 
     28        #   "sheep".singluarize #=> "sheep" 
     29        #   "word".singluarize #=> "word" 
     30        #   "the blue mailmen".singularize #=> "the blue mailman" 
     31        #   "CamelOctopi".singularize #=> "CamelOctopus" 
    2532        def singularize 
    2633          Inflector.singularize(self) 
    2734        end 
    2835 
    29         # Creates a camelcased name from an underscored name. CamelCased names LookLikeThis and under_scored_names look_like_this. 
     36        # By default, camelize converts strings to UpperCamelCase. If the argument to camelize 
     37        # is set to ":lower" then camelize produces lowerCamelCase. 
     38        # 
     39        # camelize will also convert '/' to '::' which is useful for converting paths to namespaces  
    3040        # 
    3141        # Examples 
    3242        #   "active_record".camelize #=> "ActiveRecord" 
    33         #   "raw_scaled_scorer".camelize #=> "RawScaledScorer" 
     43        #   "active_record".camelize(:lower) #=> "activeRecord" 
     44        #   "active_record/errors".camelize #=> "ActiveRecord::Errors" 
     45        #   "active_record/errors".camelize(:lower) #=> "activeRecord::Errors" 
    3446        def camelize(first_letter = :upper) 
    3547          case first_letter 
     
    4052        alias_method :camelcase, :camelize 
    4153 
    42         # Capitalizes all the words and replaces some characters in the string to create a nicer looking title. 
     54        # Capitalizes all the words and replaces some characters in the string to create 
     55        # a nicer looking title. Titleize is meant for creating pretty output. It is not 
     56        # used in the Rails internals. 
     57        # 
     58        # titleize is also aliased as as titlecase 
    4359        # 
    4460        # Examples 
     
    5167 
    5268        # The reverse of +camelize+. Makes an underscored form from the expression in the string. 
     69        #  
     70        # Changes '::' to '/' to convert namespaces to paths. 
    5371        # 
    5472        # Examples 
    5573        #   "ActiveRecord".underscore #=> "active_record" 
    56         #   "RawScaledScore".underscore #=> "raw_scaled_score" 
     74        #   "ActiveRecord::Errors".underscore #=> active_record/errors 
    5775        def underscore 
    5876          Inflector.underscore(self) 
    5977        end 
    6078 
    61         # Replaces underscores with dashes in the string 
     79        # Replaces underscores with dashes in the string. 
    6280        # 
    6381        # Example 
     
    7694        end 
    7795 
    78         # Create the name of a table like Rails does for models to table names. 
     96        # Create the name of a table like Rails does for models to table names. This method 
     97        # uses the pluralize method on the last word in the string. 
    7998        # 
    8099        # Examples 
    81100        #   "RawScaledScorer".tableize #=> "raw_scaled_scorers" 
    82101        #   "egg_and_ham".tableize #=> "egg_and_hams" 
     102        #   "fancyCategory".tableize #=> "fancy_categories" 
    83103        def tableize 
    84104          Inflector.tableize(self) 
    85105        end 
    86106 
    87         # Create a class name from a table name like Rails does for table names to models. Note that this returns a string and not a Class. 
     107        # Create a class name from a table name like Rails does for table names to models. 
     108        # Note that this returns a string and not a Class. (To convert to an actual class 
     109        # follow classify with constantize.) 
    88110        # 
    89111        # Examples 
     
    95117         
    96118        # Capitalizes the first word and turns underscores into spaces and strips _id. 
     119        # Like titleize, this is meant for creating pretty output. 
    97120        # 
    98121        # Examples 
     
    103126        end 
    104127 
    105         # Creates a foreign key name from a class name. +separate_class_name_and_id_with_underscore+ sets whether the method should put '_' between the name and 'id'. 
     128        # Creates a foreign key name from a class name. 
     129        # +separate_class_name_and_id_with_underscore+ sets whether 
     130        # the method should put '_' between the name and 'id'. 
    106131        # 
    107132        # Examples 
     
    113138        end 
    114139 
    115         # Constantize tries to find a declared constant with the name specified in the string. It raises a NameError when the name is not in CamelCase or is not initialized. 
     140        # Constantize tries to find a declared constant with the name specified 
     141        # in the string. It raises a NameError when the name is not in CamelCase 
     142        # or is not initialized. 
    116143        # 
    117144        # Examples