Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

try! bugged with Tempfile#unlink #14042

Closed
mrbrdo opened this Issue · 6 comments

3 participants

@mrbrdo
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
Collaborator

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
@mrbrdo

It does implement it.

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

You misinterpret my issue.

@mrbrdo

@dmathieu please reopen.

@dmathieu
Collaborator

:astonished:

@dmathieu dmathieu reopened this
@eval

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

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
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.