Skip to content

Commit

Permalink
Prefer Enumerable#flat_map over .map.flatten chain
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmaroli committed Feb 3, 2020
1 parent cbc62de commit 6db5ebf
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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/addressable/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}/
Expand Down

0 comments on commit 6db5ebf

Please sign in to comment.