diff --git a/.rubocop.yml b/.rubocop.yml index e780f77a42..3322983b47 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -259,6 +259,9 @@ Performance/FlatMap: Performance/MapCompact: Enabled: true +Performance/SelectMap: + Enabled: true + Performance/RedundantMerge: Enabled: true diff --git a/actionview/lib/action_view/testing/resolvers.rb b/actionview/lib/action_view/testing/resolvers.rb index 76318b7cc4..78306e4af4 100644 --- a/actionview/lib/action_view/testing/resolvers.rb +++ b/actionview/lib/action_view/testing/resolvers.rb @@ -24,10 +24,8 @@ module ActionView #:nodoc: private def template_glob(glob) - @hash.keys.select do |path| - File.fnmatch(glob, path) - end.map do |fixture| - "/#{fixture}" + @hash.keys.filter_map do |path| + "/#{path}" if File.fnmatch(glob, path) end end diff --git a/guides/rails_guides/kindle.rb b/guides/rails_guides/kindle.rb index fc8e6b97e6..dea2e775a4 100644 --- a/guides/rails_guides/kindle.rb +++ b/guides/rails_guides/kindle.rb @@ -17,7 +17,7 @@ module Kindle puts "=> Arranging html pages in document order" toc = File.read("toc.ncx") doc = Nokogiri::XML(toc).xpath("//ncx:content", "ncx" => "http://www.daisy.org/z3986/2005/ncx/") - html_pages = doc.select { |c| c[:src] }.map { |c| c[:src] }.uniq + html_pages = doc.filter_map { |c| c[:src] }.uniq generate_front_matter(html_pages) diff --git a/railties/lib/rails/info_controller.rb b/railties/lib/rails/info_controller.rb index 718060ebd6..eda66c2450 100644 --- a/railties/lib/rails/info_controller.rb +++ b/railties/lib/rails/info_controller.rb @@ -34,9 +34,7 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc: private def match_route - _routes.routes.select { |route| - yield route.path - }.map { |route| route.path.spec.to_s } + _routes.routes.filter_map { |route| route.path.spec.to_s if yield route.path } end def with_leading_slash(path) diff --git a/railties/lib/rails/test_unit/runner.rb b/railties/lib/rails/test_unit/runner.rb index fe6c17c03c..aa75f35c98 100644 --- a/railties/lib/rails/test_unit/runner.rb +++ b/railties/lib/rails/test_unit/runner.rb @@ -63,7 +63,9 @@ module Rails private def extract_filters(argv) # Extract absolute and relative paths but skip -n /.*/ regexp filters. - argv.select { |arg| path_argument?(arg) && !regexp_filter?(arg) }.map do |path| + argv.filter_map do |path| + next unless path_argument?(path) && !regexp_filter?(path) + path = path.tr("\\", "/") case when /(:\d+)+$/.match?(path)