Sha256: 3ee06c976fc4d64961c33f50de32148ed852d4ec61a23483bcea9c3c6edfaa42

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

# = 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
#
#   class A
#     extend Uninheritable
#   end
#
#   class B < A; end # => raises TypeError
#
# == AUTHORS
#
# * Austin Ziegler
#
# == COPYRIGHT
#
#   Copyright (c) 2003 Austin Ziegler
#
# == LICENSE
#
#   Ruby License
#
#   This module is free software. You may use, modify, and/or redistribute this
#   software under the same terms as Ruby.
#
#   This program is distributed in the hope that it will be useful, but WITHOUT
#   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#   FOR A PARTICULAR PURPOSE.
#

# = 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.
#
module Uninheritable
  # Redefines a class's #inherited definition to prevent subclassing of the
  # class extended by this module.
  def inherited(klass)
    raise TypeError, "Class #{self} cannot be subclassed."
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
facets-2.6.0 lib/more/facets/uninheritable.rb
facets-2.4.0 lib/facets/uninheritable.rb
facets-2.4.1 lib/facets/uninheritable.rb
facets-2.4.2 lib/more/facets/uninheritable.rb
facets-2.4.3 lib/more/facets/uninheritable.rb
facets-2.4.4 lib/more/facets/uninheritable.rb
facets-2.5.1 lib/more/facets/uninheritable.rb
facets-2.5.0 lib/more/facets/uninheritable.rb
facets-2.4.5 lib/more/facets/uninheritable.rb
facets-2.5.2 lib/more/facets/uninheritable.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/more/facets/uninheritable.rb