superclass=
type=module
library=monitor
extended=
included=

åɤƱȤƤΥ˥ǽ󶡤⥸塼Ǥ

饹 [[m:Module#include]] ꡢ֥Ȥ
[[m:Object#extend]] ꤹ뤳ȤǤΥ饹/֥Ȥ
˥ǽɲäޤ

=== 
ԡ
  require 'monitor'
    
  buf = []
  buf.extend(MonitorMixin) # ˥˥ǽɲ
  empty_cond = buf.new_cond # 󤬶Ǥ뤫ʤΤѿ
  
  # consumer
  Thread.start do
    loop do
      buf.synchronize do # å
        empty_cond.wait_while { buf.empty? } # 󤬶Ǥ֤ϥåԤ
        print buf.shift # 󤬶ǤʤʤäåƤιԤ¹
      end # å
    end
  end
  
  # producer
  while line = ARGF.gets
    buf.synchronize do # å
      buf.push(line) # ѹ(ɲ)
      empty_cond.signal # Ǥɲä줿Ȥѿ̤
    end # ǥå
  end

=== 

MonitorMixin Ͻɬפޤ
Τ褦 [[m:Object#extend]] ȤäѤ
ưŪ˽ޤ

  require 'monitor'
  buf = []
  buf.extend(MonitorMixin)

MonitorMixin 򥯥饹κݤ [[m:Module#include]] Ȥä
Ѥϡinitialize ᥽åɤ super()  super Ƥǡɬפޤ
ѡ饹 initialize ˰Ϥ super 򡢤Ǥʤ super() Ƥǲ
ܤϡ[[ref:d:spec/call#super]] 򻲾ȤƲ
㤨Сʲ MyObject Υѡ饹 Object Ǥꡢ initialize ϰդʤΤ
super ǤϤʤ super() Ƥɬפޤ

  require 'monitor'
  class MyObject
    include MonitorMixin
    
    def initialize(val)
      super()
      @value = val
    end
    
    def to_s
      synchronize {
        @value.to_s
      }
    end
  end

ʲ⻲ͤˤʤޤ

  * [[ruby-dev:9384]]
  * [[ruby-dev:9386]]
