aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/inflector.rb6
-rw-r--r--activesupport/test/inflector_test.rb6
3 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 791a2f2712..36db4dc605 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Enhance Inflector.underscore to convert '-' into '_' (as the inverse of Inflector.dasherize) [Jamis Buck]
+
* Switched to_xml to use the xml schema format for datetimes. This allows the encoding of time zones and should improve operability. [Koz]
* Added a note to the documentation for the Date related Numeric extensions to indicate that they're
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index bbc5e10579..43620757c2 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -118,7 +118,11 @@ module Inflector
end
def underscore(camel_cased_word)
- camel_cased_word.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
+ camel_cased_word.to_s.gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
end
def dasherize(underscored_word)
diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb
index d3f4a7727e..12976a6d92 100644
--- a/activesupport/test/inflector_test.rb
+++ b/activesupport/test/inflector_test.rb
@@ -302,4 +302,10 @@ class InflectorTest < Test::Unit::TestCase
assert_equal(dasherized, Inflector.dasherize(underscored))
end
end
+
+ def test_underscore_as_reverse_of_dasherize
+ UnderscoresToDashes.each do |underscored, dasherized|
+ assert_equal(underscored, Inflector.underscore(Inflector.dasherize(underscored)))
+ end
+ end
end