Sha256: 04ca518992997df537b759b9c8b39bac077cbd844cb7cadad3fba61aa130a9b5

Contents?: true

Size: 913 Bytes

Versions: 1

Compression:

Stored size: 913 Bytes

Contents

class Module

  def package( name, &block )
    @__package__ ||= {}
    return @__package__ unless block_given?
    @__package__[name.to_sym] = block
  end

  def provide_features( base, *selection )
    selection.each do |s| 
      base.class_eval( &@__package__[s.to_sym] )
    end
  end

  def use( package, *selection )
    if String === package or Symbol === package
      package = constant(package)
    end
    package.provide_features( self, *selection )
  end

end


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

=begin test

  require 'test/unit'

  class TCModule < Test::Unit::TestCase
  
    module MyPackage
      package :foo do
        def foo
          "yes"
        end
      end
    end

    class Y
      use MyPackage, :foo
    end

    def  test_package
      y = Y.new
      assert_equal( "yes", y.foo )
    end
  
  end

=end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-0.9.0 lib/mega/package.rb