Commit c66bc6a

Stephen Peasley <stephenpeasley@hotmail.com>
2013-09-26 01:23:24
movie library built and ready to rock and roll
1 parent e8a87d0
spec/lesson_one/popquiz_spec.rb
@@ -3,14 +3,24 @@ require "spec_helper"
 class CarWash
   def initialize(name = "Unknown Name", address = "Unknown Address")
     @name = name
-    @address = address
+    @address = address    
   end
   def description
     "#{@name} is located at #{@address}"
   end
+  
   def self.wash(car)
-    @car = car
-    "Your #{@car} is clean."
+    @carr = car
+    @@car = car
+    "Your #{@@car} is clean."
+  end
+  
+  def self.last_car_washed
+    @carr  
+  end
+  
+  def last_car_scrubbed
+    CarWash.instance_variable_get("@carr")
   end
 end
 
@@ -18,10 +28,11 @@ class Drink
   attr_reader :name
   attr_accessor :color
   attr_accessor :rating
+  
   def initialize(name)
     @name = name
-    @color = color
-    @rating = rating
+    # @color = color()
+    # @rating = rating()
   end
 end
 
@@ -39,6 +50,18 @@ describe 'pop quiz 1' do
       washed_car = CarWash.wash(car)
       washed_car.should == "Your #{car} is clean."
     end
+    
+    it "can access a class variable" do
+      car = "Toyota"
+      CarWash.wash(car)
+      CarWash.last_car_washed.should == car
+    end
+    
+    it "should return the last car washed at a specific car wash" do
+      car = "Jeep"
+      CarWash.wash(car)
+      CarWash.new.last_car_scrubbed.should == car
+    end
   end
 
   context :attr_ do
@@ -58,6 +81,11 @@ describe 'pop quiz 1' do
       drink.rating=5
       drink.rating.should == 5
     end
+    
+    it "should have a default colour" do
+      drink = Drink.new("tea")
+      drink.color.should == nil
+    end
   end
 end
 
spec/lesson_three/lesson_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+class Kid
+  attr_accessor :iq
+  
+  def initialize(iq)
+    @iq = iq
+  end
+end
+
+class School
+  def educate(who)
+    who.iq *= 2
+  end
+end
+
+describe "object references" do
+  it "passes by reference" do
+    kid = Kid.new(50)
+    school = School.new
+    
+    school.educate(kid)
+    kid.iq.should == 100
+  end
+end
spec/lesson_three/movie_library_spec.rb
@@ -0,0 +1,49 @@
+require "spec_helper"
+
+class Movie
+  def initialize(name)
+    @name = name
+  end
+end
+
+
+class MovieLibrary
+  attr_accessor :total_count
+  def initialize(total_count = 0)
+    @total_count = total_count
+    @array_of_movies = []
+  end
+
+  def add(movie)
+    if !@array_of_movies.include? movie
+      @array_of_movies.push movie
+      @total_count+=1
+    end
+  end
+end
+
+
+describe MovieLibrary do
+  context "when adding a movie to the library" do
+    it "should increase the total number of movies in the library" do
+      library = MovieLibrary.new
+      shawshank_redemption = Movie.new("The Shawshank Redemption")
+      chasing_amy = Movie.new("Chasing Amy")
+    
+      library.add(shawshank_redemption)
+      library.add(chasing_amy)
+      library.total_count.should == 2
+    end
+
+    it "should not allow duplicate movies into the library" do
+      library = MovieLibrary.new
+      man_on_fire = Movie.new("Man on Fire")
+      library.add(man_on_fire)
+      library.add(man_on_fire)
+      library.total_count.should == 1
+    end
+  end
+  
+  
+  
+end
\ No newline at end of file
readme.md
@@ -12,11 +12,11 @@
 * named parameters
 * symbols
 * hashes
-* object references
 
 # lession three
 
 * review
+* object references
 * arrays
 * iterators
 * enumerable