1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

use ruby 2.7's filter_map instead of select + map

Related: c3d7794, bbbc861
This commit is contained in:
Hartley McGuire 2021-04-26 17:55:33 -04:00
parent ba1ec19013
commit a3e5e8d909
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)