Commit 56a0392

Stephen Peasley <stephenpeasley@hotmail.com>
2013-09-28 14:20:18
extract to a module.
1 parent 046bf60
Changed files (1)
spec
lesson_four
spec/lesson_four/lesson_spec.rb
@@ -8,6 +8,16 @@ module LifeBoat
   end
 end
 
+module Queryable
+    def matches?
+    each do |item|
+      result = yield(item) if block_given?
+      return item if result
+    end
+    nil
+  end 
+end
+
 
 class Book
   attr_reader :title
@@ -18,6 +28,8 @@ class Book
 end
 
 class Library
+  include Queryable
+  
   def initialize(books = [])
     @books = books
   end
@@ -34,18 +46,10 @@ class Library
   
   private
   
-  def all
+  def each
     @books.each do |book|
       yield book
     end
-  end
-  
-  def matches?
-    all do |item|
-      result = yield(item) if block_given?
-      return item if result
-    end
-    nil
   end  
 end