Sha256: fc2809f80e0dcb605f0e94aa9c892f25b1e446d2d24977167e960bb2ed21e010

Contents?: true

Size: 712 Bytes

Versions: 14

Compression:

Stored size: 712 Bytes

Contents

require 'monitor'

Module.class_eval do
  def synchronize_method *methods        
    methods.each do |method|     
      raise "can't synchronize system method #{method}" if method =~ /^__/
      
      als = "sync_#{escape_method(method)}".to_sym
      
      raise "can't synchronize the '#{method}' twice!" if instance_methods.include?(als)
      
      alias_method als, method
      script = "\
def #{method} *p, &b
  @monitor ||= Monitor.new
  @monitor.synchronize{#{als} *p, &b}
end"
      class_eval script, __FILE__, __LINE__
    end
  end
  
  def synchronize_all_methods include_super = false
    methods = self.instance_methods(include_super).collect{|m| m}
    synchronize_method *methods
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ruby_ext-0.4.25 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.24 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.23 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.22 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.21 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.20 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.19 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.18 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.17 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.16 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.15 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.14 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.13 lib/ruby_ext/more/synchronize.rb
ruby_ext-0.4.12 lib/ruby_ext/more/synchronize.rb