Skip to content

Commit

Permalink
Merge pull request #378 from ashmaroli/flat-map
Browse files Browse the repository at this point in the history
Prefer Enumerable#flat_map over .map.flatten chain
  • Loading branch information
sporkmonger committed Jul 3, 2021
2 parents c1fed1c + 6db5ebf commit e9c76b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/addressable/template.rb
Expand Up @@ -657,12 +657,12 @@ def named_captures
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

Expand Down
4 changes: 2 additions & 2 deletions lib/addressable/uri.rb
Expand Up @@ -561,10 +561,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 = if leave_re
Expand Down

0 comments on commit e9c76b8

Please sign in to comment.