Bug #11512
closedDelegateClass.#public_{instance_}methods are returning difference values.
Description
Is this intended behavior?
A patch is PR#926(https://github.com/ruby/ruby/pull/926)
require 'delegate'
class Parent
def parent_public; end
protected
def parent_protected; end
end
class Child < Parent
end
class DelegatorChild < DelegateClass(Parent)
end
class Parent
def parent_public_added; end
protected
def parent_protected_added; end
end
ignores = Object.public_instance_methods | Delegator.public_instance_methods
p(Child.public_instance_methods - ignores) #=> [:parent_public, :parent_public_added]
p(Child.new.public_methods - ignores) #=> [:parent_public, :parent_public_added]
p(DelegatorChild.public_instance_methods - ignores) #=> got: [:parent_public], expected: [:parent_public, :parent_public_added]
p(DelegatorChild.new(Parent.new).public_methods - ignores) #=> got: [:parent_public, :parent_public_added, :parent_protected]], expected: [:parent_public, :parent_public_added]
Files
Updated by jeremyevans0 (Jeremy Evans) about 5 years ago
This appears to still be a bug. The patch needed a little manual help to apply, and the tests needed to be updated, but after those changes, all tests passed. Attached is an updated patch. I'll try to commit it next week unless I hear objections.
Updated by jeremyevans (Jeremy Evans) about 5 years ago
- Status changed from Open to Closed
Applied in changeset git|e8c710b11a02c6ab82b358fc671a14f378cb1974.
Fix visibility of some methods when using DelegateClass
Public instance methods added to a delegated class after the
creation of the delegate class were not returned by the
public_instance_methods class method of the delegate class.
Protected instance methods in the delegated class when the
delegate class is created were returned by the public_methods
instance method of the delegate class.
Patch mostly from Kenichi Kamiya kachick1@gmail.com in
GitHub pull request 926. Minor changes to get it to apply,
and to fix tests after applying by me.
Fixes [Bug #11512]