Defining Classes
Let’s give ourselves a simple problem to solve. Suppose we’re running a secondhand bookstore. Every week, we do stock control. A gang of clerks uses portable bar-code scanners to record every book on our shelves. Each scanner generates a comma-separated value (CSV) file containing one row for each book scanned. The row contains (among other things) the book’s ISBN and price. An extract from one of these files looks something like this:
| "Date","ISBN","Price" |
| "2013-04-12","978-1-9343561-0-4",39.45 |
| "2013-04-13","978-1-9343561-6-6",45.67 |
| "2013-04-14","978-1-9343560-7-4",36.95 |
Our job is to take all the CSV files and work out how many of each title we have, as well as the total list price of the ...
Get Programming Ruby 3.3 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.