Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/songsterr/ext/string.rb
Overview
Extend String to support #camelize method.
"active_record".camelize # => "ActiveRecord"
"active_record".camelize(:lower) # => "activeRecord"
"active_record/errors".camelize # => "ActiveRecord::Errors"
"active_record/errors".camelize(:lower) # => "activeRecord::Errors"
Instance Method Summary collapse
Instance Method Details
#camelize(first_letter = :upper) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/songsterr/ext/string.rb', line 10 def camelize(first_letter = :upper) parts = self.split('_') i = 0 parts.collect! do |p| p = p.capitalize if (i != 0 || (i == 0 && first_letter == :upper)) i += 1 p end parts.join('') end |