Skip to content

Commit a3e5e8d

Browse files
committed
use ruby 2.7's filter_map instead of select + map
Related: c3d7794, bbbc861
1 parent ba1ec19 commit a3e5e8d

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

.rubocop.yml

+3
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ Performance/FlatMap:
259259
Performance/MapCompact:
260260
Enabled: true
261261

262+
Performance/SelectMap:
263+
Enabled: true
264+
262265
Performance/RedundantMerge:
263266
Enabled: true
264267

actionview/lib/action_view/testing/resolvers.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ def to_s
2424

2525
private
2626
def template_glob(glob)
27-
@hash.keys.select do |path|
28-
File.fnmatch(glob, path)
29-
end.map do |fixture|
30-
"/#{fixture}"
27+
@hash.keys.filter_map do |path|
28+
"/#{path}" if File.fnmatch(glob, path)
3129
end
3230
end
3331

guides/rails_guides/kindle.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def generate(output_dir, mobi_outfile, logfile)
1717
puts "=> Arranging html pages in document order"
1818
toc = File.read("toc.ncx")
1919
doc = Nokogiri::XML(toc).xpath("//ncx:content", "ncx" => "http://www.daisy.org/z3986/2005/ncx/")
20-
html_pages = doc.select { |c| c[:src] }.map { |c| c[:src] }.uniq
20+
html_pages = doc.filter_map { |c| c[:src] }.uniq
2121

2222
generate_front_matter(html_pages)
2323

railties/lib/rails/info_controller.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ def routes
3434

3535
private
3636
def match_route
37-
_routes.routes.select { |route|
38-
yield route.path
39-
}.map { |route| route.path.spec.to_s }
37+
_routes.routes.filter_map { |route| route.path.spec.to_s if yield route.path }
4038
end
4139

4240
def with_leading_slash(path)

railties/lib/rails/test_unit/runner.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ def compose_filter(runnable, filter)
6363
private
6464
def extract_filters(argv)
6565
# Extract absolute and relative paths but skip -n /.*/ regexp filters.
66-
argv.select { |arg| path_argument?(arg) && !regexp_filter?(arg) }.map do |path|
66+
argv.filter_map do |path|
67+
next unless path_argument?(path) && !regexp_filter?(path)
68+
6769
path = path.tr("\\", "/")
6870
case
6971
when /(:\d+)+$/.match?(path)

0 commit comments

Comments
 (0)