From 23a900600e824036c782b4af8294327126f9208c Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Wed, 14 May 2014 19:42:29 -0700 Subject: [PATCH 1/3] Started Panda assignment --- panda.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 panda.rb diff --git a/panda.rb b/panda.rb new file mode 100644 index 0000000..658c09b --- /dev/null +++ b/panda.rb @@ -0,0 +1,16 @@ +class Vehicle + @@wheels = 4 + + attr_accessor :color, :make, :model, :color + def initialize + @color = color + @make = make + @model = model + @color = color + end + + def wheels + @@wheels + end +end + From ef11a39da5faeb5d928fdc0e2942e3d3df919287 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Wed, 14 May 2014 20:45:06 -0700 Subject: [PATCH 2/3] Finished Panda assignment --- panda.rb | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/panda.rb b/panda.rb index 658c09b..37bd54f 100644 --- a/panda.rb +++ b/panda.rb @@ -1,16 +1,46 @@ class Vehicle @@wheels = 4 - - attr_accessor :color, :make, :model, :color - def initialize + attr_accessor :color, :make, :model + + def initialize(color, make, model) @color = color @make = make @model = model - @color = color + end + + def update(hash) + unless hash[:color].nil? + @color = hash[:color] + end + unless hash[:make].nil? + @make = hash[:make] + end + unless hash[:model].nil? + @model = hash[:model] + end end def wheels - @@wheels + "This vehicle has #{@@wheels} wheels." end end +automobile = Vehicle.new("Red", "Porsche", "911") +puts automobile.wheels +puts "Created an automobile with the following information: +Make: #{automobile.make} +Model: #{automobile.model} +Color: #{automobile.color}" + +update_hash = { :color => "Green", :make => "Toyota", :model => "Tacoma" } +automobile.update(update_hash) +puts "Updated the automobile's make model and color: +Make: #{automobile.make} +Model: #{automobile.model} +Color: #{automobile.color}" + +automobile.update({:color => "Black"}) +puts "Updated the automobile's color only +Make: #{automobile.make} +Model: #{automobile.model} +Color #{automobile.color}" From fbc9e07f668417c77f51103ef9f36371987a0f9d Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Tue, 27 May 2014 19:24:10 -0700 Subject: [PATCH 3/3] Tiger assignment --- tiger.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tiger.rb diff --git a/tiger.rb b/tiger.rb new file mode 100644 index 0000000..9ba350f --- /dev/null +++ b/tiger.rb @@ -0,0 +1,38 @@ +class Vehicle + @@wheels = 4 + attr_accessor :color, :make, :model + + def initialize(color, make, model) + @color = color + @make = make + @model = model + end + + def update(hash) + unless hash[:color].nil? + @color = hash[:color] + end + unless hash[:make].nil? + @make = hash[:make] + end + unless hash[:model].nil? + @model = hash[:model] + end + end + + def wheels + "This vehicle has #{@@wheels} wheels." + end +end + +class Automobile < Vehicle + +end + +class Motorcycle < Automobile + def self.wheels + "This vehicle has 2 wheels." + end +end + +puts Motorcycle.wheels