ruby-changes:37539
From: nobu <ko1@a...>
Date: Tue, 17 Feb 2015 11:47:29 +0900 (JST)
Subject: [ruby-changes:37539] nobu:r49620 (trunk): resolv.rb: fix equality
nobu 2015-02-17 11:47:19 +0900 (Tue, 17 Feb 2015) New Revision: 49620 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49620 Log: resolv.rb: fix equality * lib/resolv.rb (Resolv::DNS::Resource#==, #hash): elements returned by Kernel#instance_variables are Symbols now. [ruby-core:68128] [Bug #10857] Added files: trunk/test/resolv/test_resource.rb Modified files: trunk/ChangeLog trunk/lib/resolv.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 49619) +++ ChangeLog (revision 49620) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Feb 17 11:47:17 2015 Nobuyoshi Nakada <nobu@r...> + + * lib/resolv.rb (Resolv::DNS::Resource#==, #hash): elements + returned by Kernel#instance_variables are Symbols now. + [ruby-core:68128] [Bug #10857] + Tue Feb 17 10:59:10 2015 SHIBATA Hiroshi <shibata.hiroshi@g...> * doc/syntax/calling_methods.rdoc: Fix documentation for "calling_methods" Index: lib/resolv.rb =================================================================== --- lib/resolv.rb (revision 49619) +++ lib/resolv.rb (revision 49620) @@ -1676,10 +1676,10 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L1676 return false unless self.class == other.class s_ivars = self.instance_variables s_ivars.sort! - s_ivars.delete "@ttl" + s_ivars.delete :@ttl o_ivars = other.instance_variables o_ivars.sort! - o_ivars.delete "@ttl" + o_ivars.delete :@ttl return s_ivars == o_ivars && s_ivars.collect {|name| self.instance_variable_get name} == o_ivars.collect {|name| other.instance_variable_get name} @@ -1692,7 +1692,7 @@ class Resolv https://github.com/ruby/ruby/blob/trunk/lib/resolv.rb#L1692 def hash # :nodoc: h = 0 vars = self.instance_variables - vars.delete "@ttl" + vars.delete :@ttl vars.each {|name| h ^= self.instance_variable_get(name).hash } Index: test/resolv/test_resource.rb =================================================================== --- test/resolv/test_resource.rb (revision 0) +++ test/resolv/test_resource.rb (revision 49620) @@ -0,0 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/test/resolv/test_resource.rb#L1 +require 'test/unit' +require 'resolv' + +class TestResolvResource < Test::Unit::TestCase + def setup + address = "192.168.0.1" + @name1 = Resolv::DNS::Resource::IN::A.new(address) + @name1.instance_variable_set(:@ttl, 100) + @name2 = Resolv::DNS::Resource::IN::A.new(address) + end + + def test_equality + bug10857 = '[ruby-core:68128] [Bug #10857]' + assert_equal(@name1, @name2, bug10857) + end + + def test_hash + bug10857 = '[ruby-core:68128] [Bug #10857]' + assert_equal(@name1.hash, @name2.hash, bug10857) + end +end Property changes on: test/resolv/test_resource.rb ___________________________________________________________________ Added: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/