зеркало из https://github.com/github/ruby.git
* lib/delegate.rb: Delegate !=, eql? and hash [ruby-core:26139]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
78f5b54f1b
Коммит
0486db01fd
|
@ -1,3 +1,7 @@
|
|||
Sun Jun 13 04:24:18 2010 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||
|
||||
* lib/delegate.rb: Delegate !=, eql? and hash [ruby-core:26139]
|
||||
|
||||
Sun Jun 13 02:12:46 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* enc/trans/utf8_mac.trans (buf_apply): fix for patterns
|
||||
|
|
|
@ -117,7 +117,7 @@
|
|||
class Delegator < BasicObject
|
||||
kernel = ::Kernel.dup
|
||||
kernel.class_eval do
|
||||
[:to_s,:inspect,:=~,:!~,:===,:<=>].each do |m|
|
||||
[:to_s,:inspect,:=~,:!~,:===,:<=>,:eql?,:hash].each do |m|
|
||||
undef_method m
|
||||
end
|
||||
end
|
||||
|
@ -187,13 +187,25 @@ class Delegator < BasicObject
|
|||
# Note: no need to specialize private_methods, since they are not forwarded
|
||||
|
||||
#
|
||||
# Returns true if two objects are considered same.
|
||||
# Returns true if two objects are considered of equal value.
|
||||
#
|
||||
def ==(obj)
|
||||
return true if obj.equal?(self)
|
||||
self.__getobj__ == obj
|
||||
end
|
||||
|
||||
#
|
||||
# Returns true if two objects are not considered of equal value.
|
||||
#
|
||||
def !=(obj)
|
||||
return false if obj.equal?(self)
|
||||
__getobj__ != obj
|
||||
end
|
||||
|
||||
def !
|
||||
!__getobj__
|
||||
end
|
||||
|
||||
#
|
||||
# This method must be overridden by subclasses and should return the object
|
||||
# method calls are being delegated to.
|
||||
|
|
Загрузка…
Ссылка в новой задаче