remove unused attributes() boilerplate

This commit is contained in:
Torsten Ruger
2014-08-19 22:54:28 +03:00
parent 4b17a1e58f
commit dd59a2f9c6
9 changed files with 15 additions and 79 deletions

View File

@@ -6,28 +6,27 @@ module Virtual
# Values must really be Constants or Variables, ie have a storage space
class Value
def == other
other.class == self.class
end
def type
raise "abstract called for #{self.class}"
end
def attributes
raise "abstract called for #{self.class}"
end
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
return true
end
def inspect
self.class.name + ".new(" + attributes.collect{|a| send(a).inspect }.join(",")+ ")"
end
private
def initialize
end
@@ -40,9 +39,6 @@ module Virtual
@type = type
end
attr_accessor :name , :type
def attributes
[:name , :type]
end
end
# The subclasses are not strictly speaking neccessary at this def point
# i just don't want to destroy the information for later optimizations
@@ -52,17 +48,11 @@ module Virtual
def initialize type
super(:return , type)
end
def attributes
[:type]
end
end
class Self < Variable
def initialize type
super(:self , type)
end
def attributes
[:type]
end
end
class Argument < Variable
end
@@ -70,4 +60,4 @@ module Virtual
end
class Temp < Variable
end
end
end