From 1b43d30bd9f456858a6918c69b5015357bec63a4 Mon Sep 17 00:00:00 2001 From: dnourie2 Date: Thu, 8 May 2014 16:39:41 -0700 Subject: [PATCH 1/2] Created Automobile class with attributes and hash --- automobile.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 automobile.rb diff --git a/automobile.rb b/automobile.rb new file mode 100644 index 0000000..e3781c1 --- /dev/null +++ b/automobile.rb @@ -0,0 +1,22 @@ +class Automobile + @@wheels = 4 + + def initialize(color, make, year) + @color = color + @make = make + @year = year + end + + def to_s + "My car is #{@color}, its make is #{@make}, and #{@year}" + end + + def car + myride = { "color" => "blue", "make" => "chevy", "year" => :"2000" } + myride.each_value {|value| puts value } + end +end + +mycar = Automobile.new('Cyberblue', 'Chevy', 2012) +puts mycar.to_s +mycar.car From d7986479d903f6db0b5caa432bc51e42a76c2fff Mon Sep 17 00:00:00 2001 From: Dana Nourie Date: Sat, 17 May 2014 19:04:04 -0700 Subject: [PATCH 2/2] Keep getting a wrong number of arguments error, and I can't figure out why. --- automobile.rb | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/automobile.rb b/automobile.rb index e3781c1..a83c4b1 100644 --- a/automobile.rb +++ b/automobile.rb @@ -1,22 +1,19 @@ class Automobile @@wheels = 4 + attr_accessor :color, :make, :model, :year - def initialize(color, make, year) - @color = color - @make = make - @year = year - end + def initialize(color, make, model, year) + @color = hash.fetch(:color, '') + @make = hash.fetch(:make, '') + @model = hash.fetch(:model, '') + @year = hash.fetch(:year, '') - def to_s - "My car is #{@color}, its make is #{@make}, and #{@year}" end - def car - myride = { "color" => "blue", "make" => "chevy", "year" => :"2000" } - myride.each_value {|value| puts value } + def to_s + "My car is #{@color}, its make and model is #{@make} and #{@model}, and the year is #{@year}." end end -mycar = Automobile.new('Cyberblue', 'Chevy', 2012) -puts mycar.to_s -mycar.car +mycar = Automobile.new([color: 'Cyberblue', make: 'Chevy', model: 'Volt', year: '2012']) +puts mycar