mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
52fcd9975d
commit
6233ed4dcd
2 changed files with 42 additions and 4 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Tue Jun 22 13:23:13 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||||
|
|
||||||
|
* lib/delegate.rb: Forward #trust, #untrust, #taint and #untaint
|
||||||
|
to both the delegator and __getobj__ [ruby-core:26138]
|
||||||
|
|
||||||
Mon Jun 21 23:41:08 2010 wanabe <s.wanabe@gmail.com>
|
Mon Jun 21 23:41:08 2010 wanabe <s.wanabe@gmail.com>
|
||||||
|
|
||||||
* eval_error.c (error_print): clear raised_flag while error-printing
|
* eval_error.c (error_print): clear raised_flag while error-printing
|
||||||
|
|
|
@ -137,7 +137,9 @@ class Delegator < BasicObject
|
||||||
__setobj__(obj)
|
__setobj__(obj)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
# Handles the magic of delegation through \_\_getobj\_\_.
|
# Handles the magic of delegation through \_\_getobj\_\_.
|
||||||
|
#
|
||||||
def method_missing(m, *args, &block)
|
def method_missing(m, *args, &block)
|
||||||
target = self.__getobj__
|
target = self.__getobj__
|
||||||
begin
|
begin
|
||||||
|
@ -222,7 +224,9 @@ class Delegator < BasicObject
|
||||||
raise NotImplementedError, "need to define `__setobj__'"
|
raise NotImplementedError, "need to define `__setobj__'"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
# Serialization support for the object returned by \_\_getobj\_\_.
|
# Serialization support for the object returned by \_\_getobj\_\_.
|
||||||
|
#
|
||||||
def marshal_dump
|
def marshal_dump
|
||||||
ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var}
|
ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var}
|
||||||
[
|
[
|
||||||
|
@ -231,7 +235,10 @@ class Delegator < BasicObject
|
||||||
__getobj__
|
__getobj__
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
# Reinitializes delegation from a serialized object.
|
# Reinitializes delegation from a serialized object.
|
||||||
|
#
|
||||||
def marshal_load(data)
|
def marshal_load(data)
|
||||||
version, vars, values, obj = data
|
version, vars, values, obj = data
|
||||||
if version == :__v2__
|
if version == :__v2__
|
||||||
|
@ -250,10 +257,36 @@ class Delegator < BasicObject
|
||||||
end
|
end
|
||||||
private :initialize_clone, :initialize_dup
|
private :initialize_clone, :initialize_dup
|
||||||
|
|
||||||
# Freeze self and target at once.
|
##
|
||||||
def freeze
|
# :method: trust
|
||||||
__getobj__.freeze
|
# Trust both the object returned by \_\_getobj\_\_ and self.
|
||||||
super
|
#
|
||||||
|
|
||||||
|
##
|
||||||
|
# :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
|
end
|
||||||
|
|
||||||
@delegator_api = self.public_instance_methods
|
@delegator_api = self.public_instance_methods
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue