Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Updated/changed unneeded tr/gsubs #5716

Merged
merged 1 commit into from

2 participants

@jurriaan

I changed a few tr and gsub calls to better/faster equivalents.

@spastorino spastorino merged commit a9398a7 into rails:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2012
  1. @jurriaan
This page is out of date. Refresh to see the latest.
View
2  actionmailer/lib/action_mailer/base.rb
@@ -696,7 +696,7 @@ def set_content_type(m, user_content_type, class_default)
# If it does not find a translation for the +subject+ under the specified scope it will default to a
# humanized version of the <tt>action_name</tt>.
def default_i18n_subject #:nodoc:
- mailer_scope = self.class.mailer_name.gsub('/', '.')
+ mailer_scope = self.class.mailer_name.tr('/', '.')
I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize)
end
View
2  actionmailer/lib/rails/generators/mailer/templates/mailer.rb
@@ -6,7 +6,7 @@ class <%= class_name %> < ActionMailer::Base
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
- # en.<%= file_path.gsub("/",".") %>.<%= action %>.subject
+ # en.<%= file_path.tr("/",".") %>.<%= action %>.subject
#
def <%= action %>
@greeting = "Hi"
View
2  actionpack/lib/action_controller/metal/data_streaming.rb
@@ -132,7 +132,7 @@ def send_file_headers!(options)
else
if !type_provided && options[:filename]
# If type wasn't provided, try guessing from file extension.
- content_type = Mime::Type.lookup_by_extension(File.extname(options[:filename]).downcase.tr('.','')) || content_type
+ content_type = Mime::Type.lookup_by_extension(File.extname(options[:filename]).downcase.delete('.')) || content_type
end
self.content_type = content_type
end
View
2  actionpack/lib/action_controller/metal/http_authentication.rb
@@ -229,7 +229,7 @@ def decode_credentials_header(request)
def decode_credentials(header)
Hash[header.to_s.gsub(/^Digest\s+/,'').split(',').map do |pair|
key, value = pair.split('=', 2)
- [key.strip.to_sym, value.to_s.gsub(/^"|"$/,'').gsub(/'/, '')]
+ [key.strip.to_sym, value.to_s.gsub(/^"|"$/,'').delete('\'')]
end]
end
View
2  actionpack/lib/action_controller/metal/redirecting.rb
@@ -93,7 +93,7 @@ def _compute_redirect_to_location(options)
_compute_redirect_to_location options.call
else
url_for(options)
- end.gsub(/[\0\r\n]/, '')
+ end.delete("\0\r\n")
end
end
end
View
4 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -244,7 +244,7 @@ def self.normalize_path(path)
end
def self.normalize_name(name)
- normalize_path(name)[1..-1].gsub("/", "_")
+ normalize_path(name)[1..-1].tr("/", "_")
end
module Base
@@ -441,7 +441,7 @@ def app_name(app)
app.railtie_name
else
class_name = app.class.is_a?(Class) ? app.name : app.class.name
- ActiveSupport::Inflector.underscore(class_name).gsub("/", "_")
+ ActiveSupport::Inflector.underscore(class_name).tr("/", "_")
end
end
View
2  actionpack/lib/action_dispatch/testing/assertions/response.rb
@@ -83,7 +83,7 @@ def normalize_argument_to_redirection(fragment)
refer
else
@controller.url_for(fragment)
- end.gsub(/[\0\r\n]/, '')
+ end.delete("\0\r\n")
end
end
end
View
4 actionpack/lib/action_view/helpers/number_helper.rb
@@ -137,12 +137,12 @@ def number_to_currency(number, options = {})
begin
value = number_with_precision(number, options.merge(:raise => true))
- format.gsub(/%n/, value).gsub(/%u/, unit).html_safe
+ format.gsub('%n', value).gsub('%u', unit).html_safe
rescue InvalidNumberError => e
if options[:raise]
raise
else
- formatted_number = format.gsub(/%n/, e.number).gsub(/%u/, unit)
+ formatted_number = format.gsub('%n', e.number).gsub('%u', unit)
e.number.to_s.html_safe? ? formatted_number.html_safe : formatted_number
end
end
View
2  activemodel/lib/active_model/errors.rb
@@ -286,7 +286,7 @@ def full_messages
# "Name is invalid"
def full_message(attribute, message)
return message if attribute == :base
- attr_name = attribute.to_s.gsub('.', '_').humanize
+ attr_name = attribute.to_s.tr('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
I18n.t(:"errors.format", {
:default => "%{attribute} %{message}",
View
2  activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -16,7 +16,7 @@ def native_database_types
# Truncates a table alias according to the limits of the current adapter.
def table_alias_for(table_name)
- table_name[0...table_alias_length].gsub(/\./, '_')
+ table_name[0...table_alias_length].tr('.', '_')
end
# Checks to see if the table +table_name+ exists on the database.
View
4 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
@@ -339,9 +339,9 @@ def columns(table_name) #:nodoc:
when /^null$/i
field["dflt_value"] = nil
when /^'(.*)'$/
- field["dflt_value"] = $1.gsub(/''/, "'")
+ field["dflt_value"] = $1.gsub("''", "'")
when /^"(.*)"$/
- field["dflt_value"] = $1.gsub(/""/, '"')
+ field["dflt_value"] = $1.gsub('""', '"')
end
SQLiteColumn.new(field['name'], field['dflt_value'], field['type'], field['notnull'].to_i == 0)
View
2  activesupport/lib/active_support/inflector/methods.rb
@@ -77,7 +77,7 @@ def camelize(term, uppercase_first_letter = true)
# "SSLError".underscore.camelize # => "SslError"
def underscore(camel_cased_word)
word = camel_cased_word.to_s.dup
- word.gsub!(/::/, '/')
+ word.gsub!('::', '/')
word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
View
2  guides/w3c_validator.rb
@@ -76,7 +76,7 @@ def show_results(error_list)
error_summary += "\n #{name}"
error_detail += "\n\n #{name} has #{errors.size} validation error(s):\n"
errors.each do |error|
- error_detail += "\n "+error.to_s.gsub("\n", "")
+ error_detail += "\n "+error.to_s.delete("\n")
end
end
View
2  railties/lib/rails/generators/named_base.rb
@@ -99,7 +99,7 @@ def plural_name
end
def i18n_scope
- @i18n_scope ||= file_path.gsub('/', '.')
+ @i18n_scope ||= file_path.tr('/', '.')
end
def table_name
View
2  railties/lib/rails/generators/resource_helpers.rb
@@ -50,7 +50,7 @@ def controller_class_name
end
def controller_i18n_scope
- @controller_i18n_scope ||= controller_file_path.gsub('/', '.')
+ @controller_i18n_scope ||= controller_file_path.tr('/', '.')
end
# Loads the ORM::Generators::ActiveModel class. This class is responsible
View
2  railties/lib/rails/railtie.rb
@@ -162,7 +162,7 @@ def railtie_name(name = nil)
protected
def generate_railtie_name(class_or_module)
- ActiveSupport::Inflector.underscore(class_or_module).gsub("/", "_")
+ ActiveSupport::Inflector.underscore(class_or_module).tr("/", "_")
end
end
View
2  railties/test/rails_info_test.rb
@@ -43,7 +43,7 @@ def test_framework_version
def test_frameworks_exist
Rails::Info.frameworks.each do |framework|
- dir = File.dirname(__FILE__) + "/../../" + framework.gsub('_', '')
+ dir = File.dirname(__FILE__) + "/../../" + framework.delete('_')
assert File.directory?(dir), "#{framework.classify} does not exist"
end
end
Something went wrong with that request. Please try again.