Module: Uninheritable
- Defined in:
- lib/mega/uninheritable.rb
Overview
:title: Uninheritable
Allows an object to declare itself as unable to be subclassed. The technique behind this is very simple (redefinition of #inherited), so this just provides an easier way to do the same thing with a consistent error message.
Usage
require 'mega/uninheritable'
class A
extend Uninheritable
end
class B < A; end # => raises TypeError
Author(s)
-
Austin Ziegler
Instance Method Summary collapse
-
#inherited(klass) ⇒ Object
Redefines a class’s #inherited definition to prevent subclassing of the class extended by this module.
Instance Method Details
#inherited(klass) ⇒ Object
Redefines a class’s #inherited definition to prevent subclassing of the class extended by this module.
50 51 52 |
# File 'lib/mega/uninheritable.rb', line 50 def inherited(klass) raise TypeError, "Class #{self} cannot be subclassed." end |