Sha256: 353495e5895f7891d3b14de2cbfec04edd4a8020dc2c8eb90b18fab5f7e0d842

Contents?: true

Size: 950 Bytes

Versions: 6

Compression:

Stored size: 950 Bytes

Contents


require 'facets/core/module/singleton_to_module'

class Module

  def inherit( mod )
    smod = mod.singleton_to_module
    #smethods -= ['included'] if Class === self
    extend smod
    include mod
    nil
  end

end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#

=begin test

  require 'test/unit'

  class TCinherit < Test::Unit::TestCase

    module Foo
      def self.x ; 10 ; end
      def y ; 20 ; end
    end

    module Bar
      inherit Foo
    end

    class X
      inherit Bar
    end

    # test

    def test_001
      assert_equal( 10, X.x )
    end

    def test_002
      x = X.new
      assert_equal( 20, x.y )
    end

    # These won't work; this solution in non-dynamic.

    #def test_004
    #  def Foo.g ; 30 ; end
    #  assert_equal( 30, Bar.g )
    #end

    #def test_005
    #  #def Foo.g ; 30 ; end
    #  assert_equal( 30, X.g )
    #end

  end

=end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
facets-1.3.0 lib/facets/core/module/inherit.rb
facets-1.3.1 lib/facets/core/module/inherit.rb
facets-1.3.2 lib/facets/core/module/inherit.rb
facets-1.3.3 lib/facets/core/module/inherit.rb
facets-1.4.0 lib/facets/core/module/inherit.rb
facets-1.4.1 lib/facets/core/module/inherit.rb