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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)