From 8ff55fdb1f6b6b65b870f9ef679e350ac5adf70f Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 19 Aug 2014 23:03:39 +0300 Subject: [PATCH] that make four (times of identical == definitions) --- lib/virtual/instruction.rb | 14 +++++++++++--- lib/virtual/type.rb | 14 +++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/virtual/instruction.rb b/lib/virtual/instruction.rb index eddee016..227a2cf0 100644 --- a/lib/virtual/instruction.rb +++ b/lib/virtual/instruction.rb @@ -15,9 +15,17 @@ module Virtual # simple thought: don't recurse for Blocks, just check their names def == other return false unless other.class == self.class - attributes.each do |a| - left = send(a) - right = other.send(a) + Sof::Util.attributes(self).each do |a| + begin + left = send(a) + rescue NoMethodError + next # not using instance variables that are not defined as attr_readers for equality + end + begin + right = other.send(a) + rescue NoMethodError + return false + end return false unless left.class == right.class if( left.is_a? Block) return false unless left.name == right.name diff --git a/lib/virtual/type.rb b/lib/virtual/type.rb index 9aff43bf..512c591d 100644 --- a/lib/virtual/type.rb +++ b/lib/virtual/type.rb @@ -6,9 +6,17 @@ module Virtual class Type def == other return false unless other.class == self.class - attributes.each do |a| - left = send(a) - right = other.send(a) + Sof::Util.attributes(self).each do |a| + begin + left = send(a) + rescue NoMethodError + next # not using instance variables that are not defined as attr_readers for equality + end + begin + right = other.send(a) + rescue NoMethodError + return false + end return false unless left.class == right.class return false unless left == right end