Closed noraj closed 21 hours ago
The thinking was that I didn't want exceptions to be the only way to bail out, so it seemed logical to also use the "truthiness" concept in Ruby, i.e. nil
and false
both evaluate to false in an conditional.
You could do an around
block, but you'd have to call .call
:
around do |global,_command,_options,_args,code|
Paint.mode = 0 unless global_options[:color]
code.call
end
Closing as this is intended and documented behavior (even though I understand it's not ideal for your use case)
Thank you for your explanation.
When I do something like that
or even like that
I get the error
error: precondtions failed
.So that my code can continue and to avoid the failure, I have to add a truthy (
true
, 1, etc.) return value.If the output of the last command in the pre block returns
nil
orfalse
(but not0
) it fails.It's what explained here: https://www.rubydoc.info/gems/gli/2.21.1/GLI/App#pre-instance_method
I wonder why this behavior was chosen, it's not really handy in many cases.