diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/delegate.rb | 16 |
2 files changed, 18 insertions, 2 deletions
@@ -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 diff --git a/lib/delegate.rb b/lib/delegate.rb index dead782bbb..2c1db88a75 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -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,7 +187,7 @@ 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) @@ -195,6 +195,18 @@ class Delegator < BasicObject 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. # |