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 Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)