Read more

Andand and SimpleDelegator

Tobias Kraze
November 15, 2012Software engineer at makandra GmbH

The very useful andand gem Show archive.org snapshot does not play very nice with Ruby's SimpleDelegator (or vice versa).

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

This following will not work:

class MyDecorator < SimpleDelegator
  def foo
  end
end

MyDecorator.new(Object.new).andand.foo

The reasons are a bit subtle, basically SimpleDelegator will "force" some methods to be delegated, so the andand method is called on the wrapped object, not the delegator.

You can fix it like this:

class Decorator < SimpleDelegator
  def andand(*)
    super
  end
end
Posted by Tobias Kraze to makandra dev (2012-11-15 16:59)