Created
May 23, 2012 02:12
-
-
Save johnnygoodman/2772856 to your computer and use it in GitHub Desktop.
Vehicle Class, Make == Instance Variable Dynamic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative './vehicle' | |
class Automobile < Vehicle | |
attr_accessor :color, :make, :model, :year | |
def initialize(hash) | |
@color = hash[:color] | |
@make = hash[:make] | |
@model = hash[:model] | |
@year = hash[:year] | |
end | |
def self.wheels | |
4 | |
end | |
#this is brittle. It'll break as soon as other instance variables are added to the Automobile class. | |
def ==(other) | |
result = true | |
[[other.color, self.color], [other.make, self.make], [other.model, self.model], [other.year, self.year]].each do |other, this| | |
puts "other: #{other} this: #{this}" | |
result = false unless other == this | |
end | |
return result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment