Skip to content

Instantly share code, notes, and snippets.

@johnnygoodman
Created May 23, 2012 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnnygoodman/2772856 to your computer and use it in GitHub Desktop.
Save johnnygoodman/2772856 to your computer and use it in GitHub Desktop.
Vehicle Class, Make == Instance Variable Dynamic
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