stevenharman/dumb_delegator

#NoMethodsError: super : no superclass method

Closed this issue · 2 comments

require 'dumb_delegator'

class A < DumbDelegator
  def bar
    'bar'
  end
end

class B < DumbDelegator
  def bar
    "foo" + super
  end
end

B.new(A.new("")).bar

=>

#irb(main):002:0> B.new(A.new("")).bar
#NoMethodError: super: no superclass method `bar' for "":B

=>from /usr/local/opt/rbenv/versions/1.9.3-p327-perf/gemsets/rmo/gems/dumb_delegator-0.5.1/lib/d>

This fixes the "issue" but just wanna highlight that it can be confusing ...
class B < DumbDelegator
def bar
"foo" + getobj.bar
end
end

Right, that makes sense as the delegated object is not in the ancestor chain foe the subclass. But a good, tricky, catch. Thanks.