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: Performance/MapCompact:
Enabled: true Enabled: true
Performance/SelectMap:
Enabled: true
Performance/RedundantMerge: Performance/RedundantMerge:
Enabled: true Enabled: true

View file

@ -24,10 +24,8 @@ module ActionView #:nodoc:
private private
def template_glob(glob) def template_glob(glob)
@hash.keys.select do |path| @hash.keys.filter_map do |path|
File.fnmatch(glob, path) "/#{path}" if File.fnmatch(glob, path)
end.map do |fixture|
"/#{fixture}"
end end
end end

View file

@ -17,7 +17,7 @@ module Kindle
puts "=> Arranging html pages in document order" puts "=> Arranging html pages in document order"
toc = File.read("toc.ncx") toc = File.read("toc.ncx")
doc = Nokogiri::XML(toc).xpath("//ncx:content", "ncx" => "http://www.daisy.org/z3986/2005/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) generate_front_matter(html_pages)

View file

@ -34,9 +34,7 @@ class Rails::InfoController < Rails::ApplicationController # :nodoc:
private private
def match_route def match_route
_routes.routes.select { |route| _routes.routes.filter_map { |route| route.path.spec.to_s if yield route.path }
yield route.path
}.map { |route| route.path.spec.to_s }
end end
def with_leading_slash(path) def with_leading_slash(path)

View file

@ -63,7 +63,9 @@ module Rails
private private
def extract_filters(argv) def extract_filters(argv)
# Extract absolute and relative paths but skip -n /.*/ regexp filters. # 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("\\", "/") path = path.tr("\\", "/")
case case
when /(:\d+)+$/.match?(path) when /(:\d+)+$/.match?(path)