Changeset 4654
- Timestamp:
- 08/03/06 21:29:07 (2 years ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/string/inflections.rb (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r4653 r4654 1 1 *SVN* 2 3 * Thoroughly document inflections. #5700 [petermichaux@gmail.com] 2 4 3 5 * Added Module#alias_attribute [Jamis/DHH]. Example: trunk/activesupport/lib/active_support/core_ext/string/inflections.rb
r4453 r4654 12 12 # Examples 13 13 # "post".pluralize #=> "posts" 14 # "octopus".pluralize #=> "octopi" 14 15 # "sheep".pluralize #=> "sheep" 16 # "words".pluralize #=> "words" 15 17 # "the blue mailman".pluralize #=> "the blue mailmen" 18 # "CamelOctopus".pluralize #=> "CamelOctopi" 16 19 def pluralize 17 20 Inflector.pluralize(self) … … 21 24 # 22 25 # 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" 25 32 def singularize 26 33 Inflector.singularize(self) 27 34 end 28 35 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 30 40 # 31 41 # Examples 32 42 # "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" 34 46 def camelize(first_letter = :upper) 35 47 case first_letter … … 40 52 alias_method :camelcase, :camelize 41 53 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 43 59 # 44 60 # Examples … … 51 67 52 68 # The reverse of +camelize+. Makes an underscored form from the expression in the string. 69 # 70 # Changes '::' to '/' to convert namespaces to paths. 53 71 # 54 72 # Examples 55 73 # "ActiveRecord".underscore #=> "active_record" 56 # " RawScaledScore".underscore #=> "raw_scaled_score"74 # "ActiveRecord::Errors".underscore #=> active_record/errors 57 75 def underscore 58 76 Inflector.underscore(self) 59 77 end 60 78 61 # Replaces underscores with dashes in the string 79 # Replaces underscores with dashes in the string. 62 80 # 63 81 # Example … … 76 94 end 77 95 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. 79 98 # 80 99 # Examples 81 100 # "RawScaledScorer".tableize #=> "raw_scaled_scorers" 82 101 # "egg_and_ham".tableize #=> "egg_and_hams" 102 # "fancyCategory".tableize #=> "fancy_categories" 83 103 def tableize 84 104 Inflector.tableize(self) 85 105 end 86 106 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.) 88 110 # 89 111 # Examples … … 95 117 96 118 # Capitalizes the first word and turns underscores into spaces and strips _id. 119 # Like titleize, this is meant for creating pretty output. 97 120 # 98 121 # Examples … … 103 126 end 104 127 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'. 106 131 # 107 132 # Examples … … 113 138 end 114 139 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. 116 143 # 117 144 # Examples