Merge pull request #42083 from SkipKayhil/use-filter-map

use ruby 2.7's filter_map instead of select + map
This commit is contained in:
Rafael França 2021-04-26 18:39:17 -04:00 committed by GitHub
commit 4c91c7f2e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 9 deletions

View File

@ -259,6 +259,9 @@ Performance/FlatMap:
Performance/MapCompact:
Enabled: true
Performance/SelectMap:
Enabled: true
Performance/RedundantMerge:
Enabled: true

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)