
import-module

2003.05.01
   
  Version: 0.78
  : Ϻ
  ᡼: sinara@blade.nagaokaut.ac.jp
  ۡڡ: <URL:http://blade.nagaokaut.ac.jp/~sinara/ruby/math/>

Ҳ

import-module ϥ⥸塼Υ󥯥롼ɤưŪ˹Ԥޤ

ˡ

reqruire "import-method"򤹤Module˰ʲΥ᥽åɤդäޤ

import_module(mod) { ... }
    mod ⥸塼ȤƼ֤ ... ¹Ԥޤ
   
    ()
    require "import-module"
    class Foo
      def hello
        puts 'hello'
      end
    end
    
    module Bar
      def hello
        puts 'bye'
      end
    end
    
    module Baz
      def hello
        puts 'good-bye'
      end
    end
    
    foo = Foo.new
    foo.hello                   #=> hello
    Foo.import_module(Bar) do
      foo.hello                 #=> bye
      Foo.import_module(Baz) do
        foo.hello               #=> good-bye
      end
      foo.hello                 #=> bye
    end
    foo.hello                   #=> hello
   
adopt_module(mod)
    mod ⥸塼ȤƼߤޤ
   
    ()
    require "import-module"
    class Foo
      def hello
        puts 'hello'
      end
    end
    
    module Bar
      def hello
        puts 'bye'
      end
    end
    
    foo = Foo.new
    Foo.adopt_module(Bar)
    foo.hello                 #=> bye
   

ޤObjectˤϼΥ᥽åɤդäޤ

import(mod) { ... }
    mod ⥸塼ȤƼ֤ ... ¹Ԥޤ
   
    ()
    require "import-module"
    class Foo
      def hello
        puts 'hello'
      end
    end
    
    module Bar
      def hello
        puts 'bye'
      end
    end
    
    foo = Foo.new
    bar = Foo.new
    foo.hello                   #=> hello
    bar.hello                   #=> hello
    foo.import(Bar) do |foo0|
      foo.hello                 #=> bye
      p foo == foo0             #=> true
      bar.hello                 #=> hello
    end
    foo.hello                   #=> hello
    bar.hello                   #=> hello
   
adopt(mod)
    mod ⥸塼ȤƼߤޤ
   
    ()
    require "import-module"
    class Foo
      def hello
        puts 'hello'
      end
    end
    
    module Bar
      def hello
        puts 'bye'
      end
    end
    
    foo = Foo.new
    bar = Foo.new
    foo.adopt(Bar)
    foo.hello                   #=> bye
    bar.hello                   #=> hello
   

ޥå

Υ饤֥ϥޥåбƤޤ

()
require "import-module"
class Foo
  def hello
    puts 'hello'
  end
end

module Bar
  def hello
    puts 'bye'
  end
end

foo = Foo.new
foo.hello #=> hello
Thread.start do
  Foo.import_module(Bar) do
    foo.hello #=> bye
  end
end
foo.hello #=> hello

ޥåбɬפǤʤϡimport-module.rb ǤϤʤ
import-module-single-thread.rb  require Ƥ᥽åɤθƤӽФ
ʤޤ

Ȥƻ

Modify Enumerable

Enumerable ΰŪѹ
require "import-module"
module EachChar
 def each(&b); split(//).each(&b); end
end
p "abc".import(EachChar){|s| s.map{|x| x.succ}}.join("") #=> "bcd"

Determinant

͹򤽤Τޤͭ͹Ȥư
require "import-module"
require "matrix"
require "rational"

module RationalDiv
  def /(other)
    Rational(self) / other
  end
end

a = Matrix[[2, 1], [3, 1]]
puts a.det   #=> 0
Fixnum.import_module(RationalDiv) do
  puts a.det #=> -1
end
puts a.det   #=> 0



RAA <URL:http://www.ruby-lang.org/en/raa.html> ˤʲΥץ򻲹ͤ
ޤ
   
  Ruby Behaviors (David Alan Black)
  scope-in-state (Keiju Ishitsuka)
  class-in-state (Keiju Ishitsuka)



0.78 (2002.11.05)
   
  ᥽åɤβĻ¸ˤĤ bug fix

0.77 (2002.11.05)
   
  proxy object  Hash  Array ѹ®

0.76 (2002.11.01)
   
  Ļ(protected)¸

0.75 (2002.10.31)
   
  set_orig_method Ƴ

0.74 (2002.10.30)
   
  Stack#update  Scope#update ذư
  Stack#export_current Ƴ
  test, test-import-module.rb test-time.rb 񤭴

0.73 (2002.10.28)
   
  Stack ѹ
  ImportModule#import_module_init ѻ
  Thread#__IMPORT_MODULE_PREFIX_proxy, stack Ƴ
  test scripts 

0.72 (2002.10.22)
   
  Import_Module::Scope.create Ƴ
  Scope_Module ѻ

0.71 (2002.10.20)
   
  Scope_Module 饹Ƴ
  optimize: &b -> b -> b -> &b
  import-module-single-thread.rb ʬΥ
  Import_Module.single_thread ѻ

0.70 (2002.10.17)
   
  Scope 饹Ƴ
  import-module-pip.rb
  import-moudle-unbound-method.rb

0.60 (2002.10.15)
   
  饹 Target, Source, Stack ʬ

0.60beta6 (2002.10.15)
   
  ѾѥѤκǸ

0.52 (2002.10.10)
   
  åȤΥ᥽åɤ
  thread safe mode ǥեȤ
  thread_safe ᥽åɤѻ
  single_thread_mode ᥽åɤɲ

0.51 (2002.10.09)
   
  ᥽åɤΥѥ᡼Ÿ (Import_Module)

0.50 (2002.10.03)
   
  scope-in-state Ѿѥμ (Import_Module)
  stack  alias ١⥸塼١ѹ
    (Import_Module_Single_Thread)
  $IMPORT_MODULE_thread_safe ѻ
  Import_Module.thread_safe Ƴ
  Super ǽ

