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

Decorator calls unexpected method or is it intentional? #826

Open
kakipo opened this issue Nov 25, 2017 · 2 comments
Open

Decorator calls unexpected method or is it intentional? #826

kakipo opened this issue Nov 25, 2017 · 2 comments

Comments

@kakipo
Copy link

kakipo commented Nov 25, 2017

This may be a possible duplicate of issue #757

Even if a decorated instance has #trust method (which overrides Object#trust), a decorator calls Object#trust instead of decorated instance's one.

Here is an example:

class Contract
  def trust
    'I TRUST YOU'
  end
end

class ContractDecorator < Draper::Decorator
  delegate_all
end

contract = Contract.new
ContractDecorator.decorate(contract).trust # =>  #<ContractDecorator:0x00557ae72f6040 @object=#<Contract:0x00557ae7315648>, @context={}>

Is it intentional or not?

@codebycliff
Copy link
Collaborator

@kakipo Sorry it took me so long to respond. I was unable to reproduce this issue. I tried to reproduce the original issue to no avail as well. Is there anyway you can create a sample app that reproduces the issue?

@carlqt
Copy link

carlqt commented Oct 2, 2018

This is not an issue, #trust is a ruby method https://ruby-doc.org/core-2.5.1/Object.html#method-i-trust

You're essentially calling #trust method on the instance of the decorator, that's why the trust method on the Contract class isn't being called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants