Backport #8005
closed
Methods made private/protected after definition are made uncallable by prepend
Added by skwosh (Alex Goldsmith) about 11 years ago.
Updated about 11 years ago.
Description
Prepending a module seems to break method resolution for methods that have been made private
or protected
via the def private *names
and def protected *names
methods.
class A
end
A.send :prepend, Module.new {} # Works if this line is removed...
class A
def foo() end
protected :foo # Also works if we use the argument-less form of "protected"...
end
A.new.respond_to? :foo, true # => true
A.new.send :foo # => NoMethodError: undefined method `foo' for #<A:...>
Note that it correctly reports that it can respond_to?...
This breaks in Rails 4 when trying to prepend to an ActiveRecord::Base (due to dynamically defined model callbacks).
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r39743.
Alex, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
vm_method.c: overrid flag of prepending method
- vm_method.c (rb_export_method): directly override the flag of method
defined in prepending class too, not adding zsuper entry.
[ruby-core:53106] [Bug #8005]
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport200
- Status changed from Closed to Assigned
- Assignee set to nagachika (Tomoyuki Chikanaga)
- Status changed from Assigned to Closed
This issue was solved with changeset r40252.
Alex, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 39742,39743: [Backport #8005]
assertions.rb: private flag
* lib/test/unit/assertions.rb (assert_respond_to): accept optional
include-private flag.
* vm_method.c (rb_export_method): directly override the flag of method
defined in prepending class too, not adding zsuper entry.
[ruby-core:53106] [Bug #8005]
Also available in: Atom
PDF
Like0
Like0Like0Like0