You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
result=Slop.parsedo |o|
o.bool'-f','--foo','it does a foo'endresult[:foo]=trueputsresult[:foo]
Okay, it writes true to the output, so far so good. But if you change the last line to puts result.foo?… it writes false! How can this be possible? Is the method access syntax not just forwarding to []? I investigated a little and it seems used_options is at blame here:
The option does exist and is set to true properly (result.option(:true) confirms this), but used_options doesn't update. Given #options returns every time I think line 54 should just be rewritten to (o = option(name.to_s.chomp("?")))&.value which works nicely.
The text was updated successfully, but these errors were encountered:
Thanks for reporting. I don't see this as a bug. result is not a hash, so mutating values inside it wouldn't do anything. The ? suffixed methods are not meant to check that the value is true, it's meant to check that the value was used. Is there a particular use-case where you think you need this behaviour?
Take this code:
Okay, it writes
true
to the output, so far so good. But if you change the last line toputs result.foo?
… it writes false! How can this be possible? Is the method access syntax not just forwarding to[]
? I investigated a little and it seemsused_options
is at blame here:slop/lib/slop/result.rb
Lines 52 to 58 in b3e382a
The option does exist and is set to true properly (
result.option(:true)
confirms this), butused_options
doesn't update. Given#options
returns every time I think line 54 should just be rewritten to(o = option(name.to_s.chomp("?")))&.value
which works nicely.The text was updated successfully, but these errors were encountered: