Closed shindakioku closed 5 years ago
About raise "A block is required"
Do you really need the custom message?
You can remove this check and my test (add test for raise when block no given) will be succesffully execute but with some edit:
assert_equal(error.message, 'A block is required')
To
assert_equal(error.message, 'no block given (yield)')
@shindakioku looks good, see my comment above
@shindakioku I'm not sure it's more readable now: https://twitter.com/yegor256/status/1060771538448859136
@yegor256 Hi. What do you think about this kind of code?
def get(key, lifetime: 60 * 60)
raise 'A block is required' unless block_given?
calc_lambda = -> { calc(key, lifetime) { yield } }
if @sync
return @mutex.synchronize { calc_lambda.call }
end
calc_lambda.call
end
Is it possible that this is a compromise solution between your understanding of the readable code and your reviewer?
@shindakioku I think the right solution would be to use DI for this coe
@yegor256