summaryrefslogtreecommitdiff
path: root/lib/delegate.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-22 04:23:59 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-22 04:23:59 +0000
commit6233ed4dcd0892b8ac2cd6acdbee3633db34b636 (patch)
tree6aaa90e984962d4a3ad2a7b5a989f8a164db9b8e /lib/delegate.rb
parent52fcd9975d57888629520e38a489a6b66396e0fd (diff)
* 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/trunk@28376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/delegate.rb')
-rw-r--r--lib/delegate.rb41
1 files changed, 37 insertions, 4 deletions
diff --git a/lib/delegate.rb b/lib/delegate.rb
index 2c1db88a75..d5ab163850 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,10 +257,36 @@ class Delegator < BasicObject
end
private :initialize_clone, :initialize_dup
- # Freeze self and target at once.
- def freeze
- __getobj__.freeze
- super
+ ##
+ # :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.
+ #
+
+ ##
+ # :method: freeze
+ # Freeze both the object returned by \_\_getobj\_\_ and self.
+ #
+
+ [:trust, :untrust, :taint, :untaint, :freeze].each do |method|
+ define_method method do
+ __getobj__.send(method)
+ super()
+ end
end
@delegator_api = self.public_instance_methods