Project

General

Profile

Actions

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).


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #8127: NoMethodError for private / protected methods with Module#prependClosed03/20/2013Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0