Andand and SimpleDelegator

Posted Over 11 years ago. Visible to the public.

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

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
Tobias Kraze
Last edit
Over 11 years ago
License
Source code in this card is licensed under the MIT License.
Posted by Tobias Kraze to makandra dev (2012-11-15 15:59)