Explicitly returning a result in a check always fails
greena13 opened this issue · comments
HealthBit Version: 0.1.8
When using an explicit return
the check always fails:
For example, the following check always fails:
LiveCheck.add('MyCheck') do
return true
end
Whereas the following works as expected:
LiveCheck.add('MyCheck') do
true
end
This is particularly problematic when you want to use a guard clause to return early:
LiveCheck.add('MyCheck') do
return true if # some condition
# ... else do something other check
end
Did you try to use break false
instead of return ?
Hey @shlima, thank you for the quick response.
I have a situation where I want a guard clause to return a successful check under some circumstances (effectively avoiding performing the real check). So, if I'm reading the Readme and source code correctly, I'm looking to return a truthy response, rather than a falsey one.
So I tried break true
and I get the same behaviour as using an explicit return
statement.
@greena13 just use next
inside a block:
HealthBit.add('Custom') do
next(true)
false
end
@shlima, I've no problem with this being the answer, but could this be documented more prominently in the readme for others?
Apologies if I've missed a recent update to the Readme you've made already.