From b76c33fead9ee12474d0e2618fb12b63b7b47850 Mon Sep 17 00:00:00 2001 From: marcandre Date: Tue, 22 Jun 2010 04:29:59 +0000 Subject: [PATCH] Backport of r28376: * lib/delegate.rb: Forward #trust, #untrust, #taint and #untaint to both the delegator and __getobj__ [ruby-core:26138] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28378 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/delegate.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/ChangeLog b/ChangeLog index c650f9082c..f676d7360c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jun 22 13:26:47 2010 Marc-Andre Lafortune + + * lib/delegate.rb: Forward #trust, #untrust, #taint and #untaint + to both the delegator and __getobj__ [ruby-core:26138] + Tue Jun 22 01:38:23 2010 Masatoshi SEKI * lib/drb/drb.rb: raise DRbConnError instead of ArgumentError if too diff --git a/lib/delegate.rb b/lib/delegate.rb index 2c1db88a75..973b0a4b95 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -137,7 +137,9 @@ class Delegator < BasicObject __setobj__(obj) end + # # Handles the magic of delegation through \_\_getobj\_\_. + # def method_missing(m, *args, &block) target = self.__getobj__ begin @@ -222,7 +224,9 @@ class Delegator < BasicObject raise NotImplementedError, "need to define `__setobj__'" end + # # Serialization support for the object returned by \_\_getobj\_\_. + # def marshal_dump ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var} [ @@ -231,7 +235,10 @@ class Delegator < BasicObject __getobj__ ] end + + # # Reinitializes delegation from a serialized object. + # def marshal_load(data) version, vars, values, obj = data if version == :__v2__ @@ -250,7 +257,36 @@ class Delegator < BasicObject end private :initialize_clone, :initialize_dup + ## + # :method: trust + # Trust both the object returned by \_\_getobj\_\_ and self. + # + + ## + # :method: untrust + # Untrust both the object returned by \_\_getobj\_\_ and self. + # + + ## + # :method: taint + # Taint both the object returned by \_\_getobj\_\_ and self. + # + + ## + # :method: untaint + # Untaint both the object returned by \_\_getobj\_\_ and self. + # + + [:trust, :untrust, :taint, :untaint].each do |method| + define_method method do + __getobj__.send(method) + super() + end + end + + # # Freeze self and target at once. + # def freeze __getobj__.freeze super