Skip to content

try! bugged with Tempfile#unlink #14042

mrbrdo opened this Issue Feb 13, 2014 · 6 comments

3 participants

mrbrdo commented Feb 13, 2014["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!.


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.

@dmathieu dmathieu closed this Feb 13, 2014
mrbrdo commented Feb 13, 2014

It does implement it.["app-icon", ".png"], Rails.root.join("tmp")).unlink works.

You misinterpret my issue.

mrbrdo commented Feb 13, 2014

@dmathieu please reopen.



@dmathieu dmathieu reopened this Feb 13, 2014
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 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.

@mrbrdo mrbrdo closed this Feb 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.