aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb7
-rw-r--r--activesupport/lib/active_support/inflector.rb8
2 files changed, 11 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index eef8a5bc89..07291032a6 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -12,8 +12,11 @@ module ActiveSupport #:nodoc:
Inflector.singularize(self)
end
- def camelize
- Inflector.camelize(self)
+ def camelize(first_letter = :upper)
+ case first_letter
+ when :upper then Inflector.camelize(self, true)
+ when :lower then Inflector.camelize(self, false)
+ end
end
alias_method :camelcase, :camelize
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index 43620757c2..ce36d3ef54 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -109,8 +109,12 @@ module Inflector
end
end
- def camelize(lower_case_and_underscored_word)
- lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
+ if first_letter_in_uppercase
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
+ else
+ lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
+ end
end
def titleize(word)