draper icon indicating copy to clipboard operation
draper copied to clipboard

Decorator calls unexpected method or is it intentional?

Open kakipo opened this issue 7 years ago • 2 comments

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?

kakipo avatar Nov 25 '17 08:11 kakipo

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

codebycliff avatar Dec 06 '17 18:12 codebycliff

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.

carlqt avatar Oct 02 '18 09:10 carlqt