Skip to content

Commit 19d6f11

Browse files
committed
Can use less code here. Avoid return in block definition
1 parent 54a1c66 commit 19d6f11

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

lib/redis/semaphore.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ def locked?(token = nil)
9494
if token
9595
@redis.hexists(grabbed_key, token)
9696
else
97-
@tokens.each do |token|
98-
return true if locked?(token)
99-
end
100-
101-
false
97+
@tokens.any? { |t| locked?(t) }
10298
end
10399
end
104100

spec/semaphore_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@
228228
end
229229

230230
it "without time support should return the same time as frozen time" do
231-
expect(semaphore.instance_variable_get(:@redis)).to receive(:time).and_raise(Redis::CommandError)
231+
expect(semaphore.instance_variable_get(:@redis)).to receive(:time)
232+
.and_raise(Redis::CommandError)
232233
expect(semaphore.send(:current_time)).to eq(Time.now)
233234
end
234235
end

0 commit comments

Comments
 (0)