Skip to content

Commit d4a093c

Browse files
committed
Refactor: Simplify Enumerator Refinement
Why This Change Is Necessary ======================================================================== The [original PR][1] was submitted by @ronen and at the time I had not looked into it sufficiently. It seems as though this code can be greatly simplified by leveraging the fact that we are already refining an `Enumerator` and therefore there is no need to wrap in another `Enumerator`. What These Changes Do To Address the Issue ======================================================================== Remove the wrapping `Enumerator` Caveats ------------------------------------------------------------------------ I'd love to have @ronen take a look at this and see if anything jumps out as being very wrong about this implementation. Side Effects Caused By This Change ======================================================================== None expected. ------------------------------------------------------------------------ **Relevant URLs:** * [Original PR Link][1] ------------------------------------------------------------------------ [1]: #126
1 parent 767ee97 commit d4a093c

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/ruby-progressbar/refinements/enumerator.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ module Refinements
33
module Enumerator
44
refine ::Enumerator do
55
def with_progressbar(options = {}, &block)
6-
chain = ::Enumerator.new do |yielder|
7-
progress_bar = ProgressBar.create(options.merge(:starting_at => 0, :total => size))
6+
progress_bar = ProgressBar.create(options.merge(:starting_at => 0, :total => size))
87

9-
each do |*args|
10-
yielder.yield(*args).tap do
11-
progress_bar.increment
12-
end
13-
end
14-
end
8+
each do |*yielded_args|
9+
progress_bar.increment
1510

16-
return chain unless block
11+
next unless block
1712

18-
chain.each(&block)
13+
yield(*yielded_args)
14+
end
1915
end
2016
end
2117
end

0 commit comments

Comments
 (0)