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 online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
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)