Editing Topic: RCR239 Project: RCR | RCRchive home

RCR 239: Module#not_redefining, #redefining, #not_redefinable

submitted by itsme213 on Wed Apr 07 2004 09:19:24 PM -0700

Status: pending


Abstract

Catch method definitions that either accidentally re-define, or accidentally fail to re-define, an existing method.

Problem

Both when subclassing, and when re-opening a class to extend it, a common error is mistakenly overriding (or failing to override) a method. This RCR lets you declare your intent to re-define (or not), and catches errors.

Proposal

Add class methods

Class#redefining

Any method defined while this is in effect should redefine an existing method; otherwise an error is raised

Class#not_redefining

Any method defined while this is in effect should not be redefining an existing method; otherwise an error is raised

Class#not_redefinable

Any method that is defined while this is in effect should not be overriden by any subclass (or extension of this class); otherwise an error is raised

Analysis

Should not affect existing code, unless they already use methods with those names.

Implementation

At least part of this can be accomplished by method_added and traversing the class inheritance and module inclusion structures. Sorry I don't have a full implementation to propose.


Back to RCRchive.


RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog