Skip to content

Commit

Permalink
Use concat instead of << to merge two arrays together.
Browse files Browse the repository at this point in the history
This way we won't create nested arrays, plus it's faster.
  • Loading branch information
si-lens committed Nov 3, 2022
1 parent c4f3eaf commit b2787e8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/faker/sports/sport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ class << self
#
# @faker.version next
def sport(include_ancient: false, include_unusual: false)
sports = fetch_all('sport.summer_olympics') + fetch_all('sport.winter_olympics') + fetch_all('sport.summer_paralympics') + fetch_all('sport.winter_paralympics')
sports << fetch_all('sport.ancient_olympics') if include_ancient
sports << fetch_all('sport.unusual') if include_unusual
sports = []
sports.concat(
fetch_all('sport.summer_olympics'),
fetch_all('sport.summer_paralympics'),
fetch_all('sport.winter_olympics'),
fetch_all('sport.winter_paralympics')
)
sports.concat(fetch_all('sport.ancient_olympics')) if include_ancient
sports.concat(fetch_all('sport.unusual')) if include_unusual
sample(sports)
end

Expand Down

0 comments on commit b2787e8

Please sign in to comment.