New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement AS::Duration#send and #try to avoid unexpected behavior #320
Conversation
since Duration inherits from BasicObject, send and try aren't implemented so they're delegated to the Integer value by method_missing. This causes unexpected behavior: d = 1.day d.inspect #=> "1 day" d.try(:inspect) || "N/A" #=> "86400" # ^^^ standard null checking goes pear-shaped
The code you submitted for |
The commit won't affect NilClass#try at all, so it won't change how try "prevents whiny nils". That is a good point about Duration's superclass, though. It's not clear to me why it inherits from BasicObject in the first place. Does anyone here on the Githubs know why that is? |
Doi, I had a brain fart there about |
Reopen after some discussion in #334 Turned out that making it inherited from Object actually have more side effect than we want. So, @misfo if you would please rebase your patch, and make it as a module that we can reuse it later, that would be awesome. Thank you for the hard work. I'm target this one for 3.2.x |
Sure will. Thanks for taking a look at this. I'll comment on this pull when I've created a new one... |
Ping. Did you make progress on this? |
@jeremy, I looked at this again and I still think
I understand that |
As a proxy, it's clearer to be explicit about what we don't want to be proxied, rather than what we do. It's easier to maintain, too. This could be a good case for a better supporting class, like |
@jeremy I was looking into this and it seems Or do you prefer Would be happy to provide a patch. /cc @josevalim |
Is this still an issue @misfo? |
Is this okay to close? |
Surely |
since Duration inherits from ::BasicObject when using Ruby 1.9, send and try aren't implemented so they're delegated to the Integer value by method_missing. This causes unexpected behavior: