draper
draper copied to clipboard
Decorator calls unexpected method or is it intentional?
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 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?
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.