Skip to content

Fix bug #9155. Problem with delegate class. #459

Closed
wants to merge 1 commit into from

4 participants

@smathieu

Problem was that a simple class like:

class X < DelegateClass(Integer)
  def initialize(value)
    value = Integer(value)
    super(value)
  end
end

would fail because Integer would call method_missing of SimpleDelegate, but that would raise an exception since the object to delegate to is not yet set (it will be when super is called).

/cc @nobu

@marcandre
Ruby Programming Language member

What exactly is the issue? The given code works without the patch, no?

@smathieu

Without the fix, the following exception is raised:

 1) Error:
TestDelegateClass#test_use_delegated_method_in_constuctor:
ArgumentError: not delegated
    /Users/simon/Documents/rainforest/ruby/lib/delegate.rb:384:in `__getobj__'
    /Users/simon/Documents/rainforest/ruby/lib/delegate.rb:77:in `method_missing'
    test/test_delegate.rb:174:in `initialize'
    test/test_delegate.rb:180:in `new'
    test/test_delegate.rb:180:in `test_use_delegated_method_in_constuctor'
@ukd1
ukd1 commented Nov 29, 2013

@marcandre this only affects 2.1 preview 2 and up.

@hsbt
Ruby Programming Language member
hsbt commented Nov 30, 2013
@ukd1
ukd1 commented Dec 4, 2013

Nobu resolved this with changeset r43984.

@marcandre
Ruby Programming Language member

👍

@marcandre marcandre closed this Dec 4, 2013
@hsbt
Ruby Programming Language member
hsbt commented Dec 4, 2013

@smathieu @ukd1 Thank you for your report!

@ukd1
ukd1 commented Dec 4, 2013

@hsbt / @marcandre no problem. The code @smathieu wrote didn't get used; is there a guide to writing these in the correct style? Should they be sent to another place except github? We'll probably end up finding more things and would like to keep helping out, but would like to understand how to better!

Russ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.