* gc.c: __size__ removed. use the length of __members__ instead.
[ruby-svn.git] / prelude.rb
blobfdf401b56a5475b5376d7758207c0b65c7a908ba
2 # Mutex
4 class Mutex
5   def synchronize
6     self.lock
7     begin
8       yield
9     ensure
10       self.unlock rescue nil
11     end
12   end
13 end
15 # Thread
17 class Thread
18   MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new
19   def self.exclusive
20     MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
21       yield
22     }
23   end
24 end
26 def require_relative(relative_feature)
27   c = caller.first
28   e = c.rindex(/:\d+:in /)
29   file = $`
30   if /\A\((.*)\)/ =~ file # eval, etc.
31     raise LoadError, "require_relative is called in #{$1}"
32   end
33   absolute_feature = File.expand_path(File.join(File.dirname(file), relative_feature))
34   require absolute_feature
35 end