提交 6c95e9b1 编写于 作者: J Jamis Buck

Enhance Inflector.underscore to convert '-' into '_' (as the inverse of Inflector.dasherize)


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3877 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 6480d497
*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
......
......@@ -118,7 +118,11 @@ def titleize(word)
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)
......
......@@ -302,4 +302,10 @@ def test_dasherize
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册