mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
853dd6cabe
* include/ruby/intern.h: declare rb_dir_getwd. * dir.c (rb_dir_getwd): copied from dir_s_getwd to export. (dir_s_getwd): use rb_dir_getwd. * file.c (rb_file_s_realpath): new method File.realpath. (rb_file_s_realdirpath): new method File.realdirpath. * lib/pathname.rb (Pathname#realpath): use File.realpath. (Pathname#realdirpath): use File.realdirpath. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26290 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
38 lines
665 B
Ruby
38 lines
665 B
Ruby
|
|
# Mutex
|
|
|
|
class Mutex
|
|
def synchronize
|
|
self.lock
|
|
begin
|
|
yield
|
|
ensure
|
|
self.unlock rescue nil
|
|
end
|
|
end
|
|
end
|
|
|
|
# Thread
|
|
|
|
class Thread
|
|
MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new
|
|
def self.exclusive
|
|
MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{
|
|
yield
|
|
}
|
|
end
|
|
end
|
|
|
|
module Kernel
|
|
module_function
|
|
def require_relative(relative_feature)
|
|
c = caller.first
|
|
e = c.rindex(/:\d+:in /)
|
|
file = $`
|
|
if /\A\((.*)\)/ =~ file # eval, etc.
|
|
raise LoadError, "require_relative is called in #{$1}"
|
|
end
|
|
absolute_feature = File.join(File.dirname(File.realpath(file)), relative_feature)
|
|
require absolute_feature
|
|
end
|
|
end
|