From 6db5ebfef2b6b5a63229807ff04dca3eeb87c16c Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 3 Feb 2020 23:00:56 +0530 Subject: [PATCH] Prefer Enumerable#flat_map over .map.flatten chain --- lib/addressable/template.rb | 4 ++-- lib/addressable/uri.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/addressable/template.rb b/lib/addressable/template.rb index 26966953..d0525f32 100644 --- a/lib/addressable/template.rb +++ b/lib/addressable/template.rb @@ -691,12 +691,12 @@ def transform(name, value) def ordered_variable_defaults @ordered_variable_defaults ||= begin expansions, _ = parse_template_pattern(pattern) - expansions.map do |capture| + expansions.flat_map do |capture| _, _, varlist = *capture.match(EXPRESSION) varlist.split(',').map do |varspec| varspec[VARSPEC, 1] end - end.flatten + end end end diff --git a/lib/addressable/uri.rb b/lib/addressable/uri.rb index 71a806bf..8f5003c6 100644 --- a/lib/addressable/uri.rb +++ b/lib/addressable/uri.rb @@ -548,10 +548,10 @@ def self.normalize_component(component, character_class= leave_re = if leave_encoded.length > 0 character_class = "#{character_class}%" unless character_class.include?('%') - "|%(?!#{leave_encoded.chars.map do |char| + "|%(?!#{leave_encoded.chars.flat_map do |char| seq = SEQUENCE_ENCODING_TABLE[char] [seq.upcase, seq.downcase] - end.flatten.join('|')})" + end.join('|')})" end character_class = /[^#{character_class}]#{leave_re}/