Skip to content
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

try! bugged with Tempfile#unlink #14042

Closed
mrbrdo opened this issue Feb 13, 2014 · 6 comments
Closed

try! bugged with Tempfile#unlink #14042

mrbrdo opened this issue Feb 13, 2014 · 6 comments

Comments

@mrbrdo
Copy link
Contributor

mrbrdo commented Feb 13, 2014

Tempfile.new(["app-icon", ".png"], Rails.root.join("tmp")).try!(:unlink)
NoMethodError: undefined method `unlink' for #<File:0x00000108ebbf00>
from /x/.rvm/gems/ruby-2.1.0@x/gems/activesupport-4.0.2/lib/active_support/core_ext/object/try.rb:55:in `public_send'

Works fine without try!.

@dmathieu
Copy link
Contributor

See try!'s documentation

Same as #try, but will raise a NoMethodError exception if the receiving is not nil and does not implemented the tried method.

So what you're seeing is the appropriate behavior.

@mrbrdo
Copy link
Contributor Author

mrbrdo commented Feb 13, 2014

It does implement it.

Tempfile.new(["app-icon", ".png"], Rails.root.join("tmp")).unlink works.

You misinterpret my issue.

@mrbrdo
Copy link
Contributor Author

mrbrdo commented Feb 13, 2014

@dmathieu please reopen.

@dmathieu
Copy link
Contributor

😲

@dmathieu dmathieu reopened this Feb 13, 2014
@eval
Copy link
Contributor

eval commented Feb 14, 2014

I guess this is relevant:

Please also note that +try+ is defined on +Object+, therefore it won't work

with instances of classes that do not have +Object+ among their ancestors,

like direct subclasses of +BasicObject+. For example, using +try+ with

+SimpleDelegator+ will delegate +try+ to the target instead of calling it on

delegator itself.

@mrbrdo
Copy link
Contributor Author

mrbrdo commented Feb 14, 2014

Yes, I thought that might have something to do it. It seems Tempfile is defined as subclass of DelegateClass. Too bad, since it is from stdlib. But I guess there is nothing we can do about it.
Closing.

@mrbrdo mrbrdo closed this as completed Feb 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants