Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb,
lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb
Overview
Removes indentation Add colors
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#camelize(first_letter = :upper) ⇒ Object
(also: #camelcase)
By default,
camelize
converts strings to UpperCamelCase. -
#classify ⇒ Object
Create a class name from a plural table name like Rails does for table names to models.
-
#constantize ⇒ Object
constantize
tries to find a declared constant with the name specified in the string. -
#pluralize ⇒ Object
Returns the plural form of the word in the string.
-
#singularize ⇒ Object
Returns the singular form of the word in the string.
- #undent ⇒ Object
-
#underscore ⇒ Object
The reverse of
camelize
.
Class Method Details
.colors ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb', line 202 def self.colors @_colors ||= { :clear => 0, :bold => 1, :black => 30, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36, :white => 37 } end |
Instance Method Details
#camelize(first_letter = :upper) ⇒ Object Also known as: camelcase
By default, camelize
converts strings to UpperCamelCase. If the argument to camelize is set to :lower
then camelize produces lowerCamelCase.
camelize
will also convert ‘/’ to ‘::’ which is useful for converting paths to namespaces.
"active_record".camelize # => "ActiveRecord"
"active_record".camelize(:lower) # => "activeRecord"
"active_record/errors".camelize # => "ActiveRecord::Errors"
"active_record/errors".camelize(:lower) # => "activeRecord::Errors"
87 88 89 90 91 92 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb', line 87 def camelize(first_letter = :upper) case first_letter when :upper then ActiveSupport::Inflector.camelize(self, true) when :lower then ActiveSupport::Inflector.camelize(self, false) end end |
#classify ⇒ Object
Create a class name from a plural table name like Rails does for table names to models. Note that this returns a string and not a class. (To convert to an actual class follow classify
with constantize
.)
"egg_and_hams".classify # => "EggAndHam"
"posts".classify # => "Post"
Singular names are not handled correctly.
"business".classify # => "Busines"
107 108 109 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb', line 107 def classify ActiveSupport::Inflector.classify(self) end |
#constantize ⇒ Object
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.
"Module".constantize # => Module
"Class".constantize # => Class
60 61 62 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb', line 60 def constantize ActiveSupport::Inflector.constantize(self) end |
#pluralize ⇒ Object
Returns the plural form of the word in the string.
"post".pluralize # => "posts"
"octopus".pluralize # => "octopi"
"sheep".pluralize # => "sheep"
"words".pluralize # => "words"
"the blue mailman".pluralize # => "the blue mailmen"
"CamelOctopus".pluralize # => "CamelOctopi"
34 35 36 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb', line 34 def pluralize ActiveSupport::Inflector.pluralize(self) end |
#singularize ⇒ Object
Returns the singular form of the word in the string.
"posts".singularize # => "post"
"octopi".singularize # => "octopus"
"sheep".singularize # => "sheep"
"words".singularize # => "word"
"the blue mailmen".singularize # => "the blue mailman"
"CamelOctopi".singularize # => "CamelOctopus"
48 49 50 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb', line 48 def singularize ActiveSupport::Inflector.singularize(self) end |
#undent ⇒ Object
223 224 225 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb', line 223 def undent gsub(/^.{#{slice(/^ +/).size}}/, '') end |
#underscore ⇒ Object
The reverse of camelize
. Makes an underscored, lowercase form from the expression in the string.
underscore
will also change ‘::’ to ‘/’ to convert namespaces to paths.
"ActiveRecord".underscore # => "active_record"
"ActiveRecord::Errors".underscore # => active_record/errors
72 73 74 |
# File 'lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/support_lite.rb', line 72 def underscore ActiveSupport::Inflector.underscore(self) end |