Project

inherit

0.0
No commit activity in last 3 years
No release in over 3 years
Avoid the anti-pattern of `def self.included(base); base.extend …; end`, without getting lost in subclassing.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 5.3.0
 Project Readme

README

Summary

Avoid the anti-pattern of def self.included(base); base.extend …; end, without getting lost in subclassing.

Installation

gem install inherit

Usage

require 'inherit'

module Inheritable
  module Constants
    Foo = "Nice constant!"
  end
  module ClassMethods
    def funky
      "Funky class method!"
    end
  end
  module InstanceMethods
    def rad
      "Rad instance method!"
    end
  end
  def self.inherited(subclass)
    puts "#{self} got inherited by #{subclass}"
  end
  def self.extended(object)
    puts "#{self} extended #{object}"
  end
end

class Example
  inherit Inheritable # -> "Inheritable got inherited by Example"
end
Example::Foo                  # => "Nice constant!"
Example.funky                 # => "Funky class method!"
Example.new.rad               # => "Rad instance method!"
a_string = "a string"
a_string.inherit Inheritable  # -> "Inheritable extended a string"
a_string.singleton_class::Foo # => "Nice constant!"
a_string.rad                  # => "Rad instance method!"

Description

Avoid the anti-pattern of def self.included(base); base.extend …; end, without getting lost in subclassing.

Links

License

You can use this code under the {file:LICENSE.txt BSD-2-Clause License}, free of charge. If you need a different license, please ask the author.