Permalink
Browse files

prefer tr to gsub for replacing characters

  • Loading branch information...
1 parent 5cff94f commit 6bd7023e2feec50472f10093340e13a2b23ebde1 @fxn fxn committed Feb 13, 2012
Showing with 2 additions and 2 deletions.
  1. +2 −2 activesupport/lib/active_support/inflector/methods.rb
@@ -94,7 +94,7 @@ def humanize(lower_case_and_underscored_word)
result = lower_case_and_underscored_word.to_s.dup
inflections.humans.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
result.gsub!(/_id$/, "")
- result.gsub!(/_/, ' ')
+ result.tr!('_', ' ')
result.gsub(/([a-z\d]*)/i) { |match|
"#{inflections.acronyms[match] || match.downcase}"
}.gsub(/^\w/) { $&.upcase }
@@ -146,7 +146,7 @@ def classify(table_name)
# Example:
# "puni_puni" # => "puni-puni"
def dasherize(underscored_word)
- underscored_word.gsub(/_/, '-')
+ underscored_word.tr('_', '-')
end
# Removes the module part from the expression in the string:

0 comments on commit 6bd7023

Please sign in to comment.