* lib/delegate.rb: catch up with class local variable (@_v) spec.

* lib/singleton.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-02-14 16:50:16 +00:00
parent fdf4aa982f
commit 970df0d138
4 changed files with 29 additions and 23 deletions

View File

@ -1,3 +1,9 @@
Thu Feb 15 01:43:45 2007 Koichi Sasada <ko1@atdot.net>
* lib/delegate.rb: catch up with class local variable (@_v) spec.
* lib/singleton.rb: ditto.
Wed Feb 14 22:52:43 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp> Wed Feb 14 22:52:43 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c (ole_variant2val): VC++6 does not * ext/win32ole/win32ole.c (ole_variant2val): VC++6 does not

View File

@ -95,15 +95,15 @@
# class SimpleDelegator < Delegator # class SimpleDelegator < Delegator
# def initialize(obj) # def initialize(obj)
# super # pass obj to Delegator constructor, required # super # pass obj to Delegator constructor, required
# @_sd_obj = obj # store obj for future use # @delegate_sd_obj = obj # store obj for future use
# end # end
# #
# def __getobj__ # def __getobj__
# @_sd_obj # return object we are delegating to, required # @delegate_sd_obj # return object we are delegating to, required
# end # end
# #
# def __setobj__(obj) # def __setobj__(obj)
# @_sd_obj = obj # change delegation object, a feature we're providing # @delegate_sd_obj = obj # change delegation object, a feature we're providing
# end # end
# #
# # ... # # ...
@ -219,7 +219,7 @@ end
class SimpleDelegator<Delegator class SimpleDelegator<Delegator
# Returns the current object method calls are being delegated to. # Returns the current object method calls are being delegated to.
def __getobj__ def __getobj__
@_sd_obj @delegate_sd_obj
end end
# #
@ -238,7 +238,7 @@ class SimpleDelegator<Delegator
# #
def __setobj__(obj) def __setobj__(obj)
raise ArgumentError, "cannot delegate to self" if self.equal?(obj) raise ArgumentError, "cannot delegate to self" if self.equal?(obj)
@_sd_obj = obj @delegate_sd_obj = obj
end end
end end
@ -269,11 +269,11 @@ def DelegateClass(superclass)
klass.module_eval { klass.module_eval {
include Delegator::MethodDelegation include Delegator::MethodDelegation
def __getobj__ # :nodoc: def __getobj__ # :nodoc:
@_dc_obj @delegate_dc_obj
end end
def __setobj__(obj) # :nodoc: def __setobj__(obj) # :nodoc:
raise ArgumentError, "cannot delegate to self" if self.equal?(obj) raise ArgumentError, "cannot delegate to self" if self.equal?(obj)
@_dc_obj = obj @delegate_dc_obj = obj
end end
} }
for method in methods for method in methods
@ -281,7 +281,7 @@ def DelegateClass(superclass)
klass.module_eval <<-EOS, __FILE__, __LINE__+1 klass.module_eval <<-EOS, __FILE__, __LINE__+1
def #{method}(*args, &block) def #{method}(*args, &block)
begin begin
@_dc_obj.__send(:#{method}, *args, &block) @delegate_dc_obj.__send(:#{method}, *args, &block)
rescue rescue
$@[0,2] = nil $@[0,2] = nil
raise raise

View File

@ -39,7 +39,7 @@
# method body is a simple: # method body is a simple:
# #
# def Klass.instance() # def Klass.instance()
# return @__instance__ # return @singleton__instance__
# end # end
# #
# * Klass._load(str) - calling Klass.instance() # * Klass._load(str) - calling Klass.instance()
@ -101,16 +101,16 @@ module Singleton
class << Singleton class << Singleton
def __init__(klass) def __init__(klass)
klass.instance_eval { klass.instance_eval {
@__instance__ = nil @singleton__instance__ = nil
@__mutex__ = Mutex.new @singleton__mutex__ = Mutex.new
} }
def klass.instance def klass.instance
return @__instance__ if @__instance__ return @singleton__instance__ if @singleton__instance__
@__mutex__.synchronize { @singleton__mutex__.synchronize {
return @__instance__ if @__instance__ return @singleton__instance__ if @singleton__instance__
@__instance__ = new() @singleton__instance__ = new()
} }
@__instance__ @singleton__instance__
end end
klass klass
end end
@ -177,13 +177,13 @@ end
class << Ups class << Ups
def _instantiate? def _instantiate?
@enter.push Thread.current[:i] @enter.push Thread.current[:i]
while false.equal?(@__instance__) while false.equal?(@singleton__instance__)
@__mutex__.unlock @singleton__mutex__.unlock
sleep 0.08 sleep 0.08
@__mutex__.lock @singleton__mutex__.lock
end end
@leave.push Thread.current[:i] @leave.push Thread.current[:i]
@__instance__ @singleton__instance__
end end
def __sleep def __sleep

View File

@ -1,7 +1,7 @@
#define RUBY_VERSION "1.9.0" #define RUBY_VERSION "1.9.0"
#define RUBY_RELEASE_DATE "2007-02-14" #define RUBY_RELEASE_DATE "2007-02-15"
#define RUBY_VERSION_CODE 190 #define RUBY_VERSION_CODE 190
#define RUBY_RELEASE_CODE 20070214 #define RUBY_RELEASE_CODE 20070215
#define RUBY_PATCHLEVEL 0 #define RUBY_PATCHLEVEL 0
#define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MAJOR 1
@ -9,7 +9,7 @@
#define RUBY_VERSION_TEENY 0 #define RUBY_VERSION_TEENY 0
#define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_YEAR 2007
#define RUBY_RELEASE_MONTH 2 #define RUBY_RELEASE_MONTH 2
#define RUBY_RELEASE_DAY 14 #define RUBY_RELEASE_DAY 15
RUBY_EXTERN const char ruby_version[]; RUBY_EXTERN const char ruby_version[];
RUBY_EXTERN const char ruby_release_date[]; RUBY_EXTERN const char ruby_release_date[];