Skip to content

Instantly share code, notes, and snippets.

@r3nya
Last active December 15, 2015 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r3nya/5295679 to your computer and use it in GitHub Desktop.
Save r3nya/5295679 to your computer and use it in GitHub Desktop.
For Mono
class Car
attr_accessor :name, :year, :price
def initialize(name, year, price)
@name = name
@year = year
@price = price
end
def get_type
self.class
end
def view_car
"name: #{self.name}, type: #{self.get_type}, year: #{self.year}, price: #{self.price}"
end
end
class Jeep < Car
end
class Sedan < Car
end
class Garbage
attr_accessor :name
def initialize(name)
@name = name
@garage_list = []
end
def insert(car)
@garage_list << car
end
def get_list
@garage_list.each { |i|
puts i.view_car
}
end
def search_name(car_name)
@garage_list.each { |i|
if i.name.to_s.capitalize == car_name.to_s.capitalize then
puts "Found! #{i.view_car}"
else
puts "Not found"
end
}
end
def search_type(type_car)
@garage_list.each { |i|
if i.get_type.to_s.capitalize == type_car.to_s.capitalize then
puts "Found! #{i.view_car}"
else
puts "Not found"
end
}
end
def delete(car)
@garage_list.delete(car)
puts "Car #{car.name} deleted from garbage #{self.name}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment