module BinarySearch # Used when indexing. You can create subclass to give the indexer the data # it needs. class DataSource # Returns the next record. The method in this class is abstract (or it # tries to) It raises an exception telling you to implement it. def next raise 'you must implement this method!' end end # A DataSource which reads from a text file. class FileDataSource < DataSource # Creates a new FileDataSource using the value of fname as the file name. def initialize(fname) @file = File.open(fname, 'r') end # Closes the file. def close @file.close @file = nil end # Reads the next line. def next @file.gets end end end