Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/amazon/mws/lib/extensions.rb
Direct Known Subclasses
Amazon::MWS::Authentication::QueryString, Amazon::MWS::Authentication::Signature
Instance Method Summary collapse
-
#camelize(first_letter_in_uppercase = true) ⇒ Object
By default,
camelizeconverts strings to UpperCamelCase.
Instance Method Details
#camelize(first_letter_in_uppercase = true) ⇒ Object
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.
Examples:
"active_record".camelize # => "ActiveRecord"
"active_record".camelize(:lower) # => "activeRecord"
"active_record/errors".camelize # => "ActiveRecord::Errors"
"active_record/errors".camelize(:lower) # => "activeRecord::Errors"
35 36 37 38 39 40 41 |
# File 'lib/amazon/mws/lib/extensions.rb', line 35 def camelize(first_letter_in_uppercase = true) if first_letter_in_uppercase self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } else self.to_s.first.downcase + camelize(lower_case_and_underscored_word)[1..-1] end end |