Browse files

Avoid Symbol#to_proc since is slow for Ruby 1.8.7

  • Loading branch information...
1 parent 2115068 commit 8508e0d249ecf7de52cd6827f50006f6817ffa0a @guilleiguaran committed Jul 23, 2011
View
4 actionpack/lib/action_controller/metal.rb
@@ -14,8 +14,8 @@ class MiddlewareStack < ActionDispatch::MiddlewareStack #:nodoc:
class Middleware < ActionDispatch::MiddlewareStack::Middleware #:nodoc:
def initialize(klass, *args, &block)
options = args.extract_options!
- @only = Array(options.delete(:only)).map(&:to_s)
- @except = Array(options.delete(:except)).map(&:to_s)
+ @only = Array(options.delete(:only)).map{ |action| action.to_s }
+ @except = Array(options.delete(:except)).map{ |action| action.to_s }
args << options unless options.empty?
super
end
View
2 actionpack/lib/action_controller/metal/hide_actions.rb
@@ -24,7 +24,7 @@ module ClassMethods
# ==== Parameters
# * <tt>args</tt> - A list of actions
def hide_action(*args)
- self.hidden_actions = hidden_actions.dup.merge(args.map(&:to_s)).freeze
+ self.hidden_actions = hidden_actions.dup.merge(args.map{ |arg| arg.to_s }).freeze
end
def inherited(klass)
View
4 actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -177,8 +177,8 @@ def _set_wrapper_defaults(options, model=nil)
controller_name.singularize
end
- options[:include] = Array.wrap(options[:include]).collect(&:to_s) if options[:include]
- options[:exclude] = Array.wrap(options[:exclude]).collect(&:to_s) if options[:exclude]
+ options[:include] = Array.wrap(options[:include]).collect{ |attr| attr.to_s } if options[:include]
+ options[:exclude] = Array.wrap(options[:exclude]).collect{ |attr| attr.to_s } if options[:exclude]
options[:format] = Array.wrap(options[:format])
self._wrapper_options = options
View
6 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -891,9 +891,9 @@ def default_actions
def actions
if only = @options[:only]
- Array(only).map(&:to_sym)
+ Array(only).map{ |action| action.to_sym }
elsif except = @options[:except]
- default_actions - Array(except).map(&:to_sym)
+ default_actions - Array(except).map{ |action| action.to_sym }
else
default_actions
end
@@ -1466,7 +1466,7 @@ def name_for_action(as, action) #:nodoc:
[name_prefix, member_name, prefix]
end
- candidate = name.select(&:present?).join("_").presence
+ candidate = name.select{ |n| n.present? }.join("_").presence
candidate unless as.nil? && @set.routes.find { |r| r.name == candidate }
end
end
View
2 actionpack/lib/action_dispatch/routing/route_set.rb
@@ -87,7 +87,7 @@ def initialize
end
def helper_names
- self.module.instance_methods.map(&:to_s)
+ self.module.instance_methods.map{ |method| method.to_s }
end
def clear!
View
2 actionpack/lib/action_dispatch/testing/assertions/selector.rb
@@ -276,7 +276,7 @@ def assert_select(*args, &block)
end
elsif match_with = equals[:html]
matches.delete_if do |match|
- html = match.children.map(&:to_s).join
+ html = match.children.map{ |child| child.to_s }.join
html.strip! unless NO_STRIP.include?(match.name)
unless match_with.is_a?(Regexp) ? (html =~ match_with) : (html == match_with.to_s)
content_mismatch ||= build_message(message, "<?> expected but was\n<?>.", match_with, html)
View
2 actionpack/lib/action_view/template/resolver.rb
@@ -78,7 +78,7 @@ def cached(key, path_info, details, locals) #:nodoc:
scope = @cached[key][name][prefix][partial]
cache = scope[locals]
- mtime = cache && cache.map(&:updated_at).max
+ mtime = cache && cache.map{ |template| template.updated_at }.max
if !mtime || fresh.empty? || fresh.any? { |t| t.updated_at > mtime }
scope[locals] = fresh
View
2 actionpack/lib/action_view/test_case.rb
@@ -205,7 +205,7 @@ def view
}
def _user_defined_ivars
- instance_variables.map(&:to_s) - INTERNAL_IVARS
+ instance_variables.map{ |variable| variable.to_s } - INTERNAL_IVARS
end
# Returns a Hash of instance variables and their values, as defined by
View
2 actionpack/lib/action_view/testing/resolvers.rb
@@ -35,7 +35,7 @@ def query(path, exts, formats)
:virtual_path => path.virtual, :format => format, :updated_at => updated_at)
end
- templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size }
+ templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject{ |capture| capture.blank? }.size }
end
end
View
2 activemodel/lib/active_model/mass_assignment_security/permission_set.rb
@@ -5,7 +5,7 @@ module MassAssignmentSecurity
class PermissionSet < Set
def +(values)
- super(values.map(&:to_s))
+ super(values.map{ |value| value.to_s })
end
def include?(key)
View
4 activemodel/lib/active_model/serialization.rb
@@ -71,9 +71,9 @@ def serializable_hash(options = nil)
attribute_names = attributes.keys.sort
if only = options[:only]
- attribute_names &= Array.wrap(only).map(&:to_s)
+ attribute_names &= Array.wrap(only).map{ |n| n.to_s }
elsif except = options[:except]
- attribute_names -= Array.wrap(except).map(&:to_s)
+ attribute_names -= Array.wrap(except).map{ |n| n.to_s }
end
method_names = Array.wrap(options[:methods]).select { |n| respond_to?(n) }
View
2 activerecord/lib/active_record/migration.rb
@@ -608,7 +608,7 @@ def migrations(paths)
MigrationProxy.new(name, version, file)
end
- migrations.sort_by(&:version)
+ migrations.sort_by{ |migration| migration.version }
end
private
View
2 activerecord/lib/active_record/test_case.rb
@@ -15,7 +15,7 @@ def cleanup_identity_map
# Backport skip to Ruby 1.8. test/unit doesn't support it, so just
# make it a noop.
- unless instance_methods.map(&:to_s).include?("skip")
+ unless instance_methods.map{ |method| method.to_s }.include?("skip")
def skip(message)
end
end
View
2 activeresource/lib/active_resource/base.rb
@@ -977,7 +977,7 @@ def schema
# gathered from the provided <tt>schema</tt>, or from the attributes
# set on this instance after it has been fetched from the remote system.
def known_attributes
- self.class.known_attributes + self.attributes.keys.map(&:to_s)
+ self.class.known_attributes + self.attributes.keys.map{ |key| key.to_s }
end
View
6 activesupport/lib/active_support/core_ext/module/method_names.rb
@@ -1,14 +1,14 @@
class Module
if instance_methods[0].is_a?(Symbol)
def instance_method_names(*args)
- instance_methods(*args).map(&:to_s)
+ instance_methods(*args).map{ |method| method.to_s }
end
def method_names(*args)
- methods(*args).map(&:to_s)
+ methods(*args).map{ |method| method.to_s }
end
else
alias_method :instance_method_names, :instance_methods
alias_method :method_names, :methods
end
-end
+end
View
2 activesupport/lib/active_support/log_subscriber.rb
@@ -73,7 +73,7 @@ def log_subscribers
def flushable_loggers
@@flushable_loggers ||= begin
- loggers = log_subscribers.map(&:logger)
+ loggers = log_subscribers.map{ |subscriber| subscriber.logger }
loggers.uniq!
loggers.select { |l| l.respond_to?(:flush) }
end
View
2 activesupport/lib/active_support/ordered_hash.rb
@@ -6,7 +6,7 @@
require 'yaml'
YAML.add_builtin_type("omap") do |type, val|
- ActiveSupport::OrderedHash[val.map(&:to_a).map(&:first)]
+ ActiveSupport::OrderedHash[val.map{ |v| v.to_a }.map{ |v| v.first }]
end
module ActiveSupport
View
3 railties/lib/rails/engine.rb
@@ -411,8 +411,7 @@ def load_console(app=self)
end
def eager_load!
- railties.all(&:eager_load!)
-
+ railties.all { |r| r.eager_load! }
config.eager_load_paths.each do |load_path|
matcher = /\A#{Regexp.escape(load_path)}\/(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
View
4 railties/lib/rails/engine/railties.rb
@@ -20,11 +20,11 @@ def plugins
end
def self.railties
- @railties ||= ::Rails::Railtie.subclasses.map(&:instance)
+ @railties ||= ::Rails::Railtie.subclasses.map{ |subclass| subclass.instance }
end
def self.engines
- @engines ||= ::Rails::Engine.subclasses.map(&:instance)
+ @engines ||= ::Rails::Engine.subclasses.map{ |subclass| subclass.instance }
end
delegate :railties, :engines, :to => "self.class"

0 comments on commit 8508e0d

Please sign in to comment.