1 00:00:00,320 --> 00:00:05,470 Okay, so we've got our contact, phone number, and address classes all set up. 2 00:00:05,470 --> 00:00:09,480 Now our contact when we initialize it has addresses and 3 00:00:09,480 --> 00:00:14,030 phone numbers, but remember we're building an address book here. 4 00:00:14,030 --> 00:00:18,060 So an address book is going to have many contacts. 5 00:00:18,060 --> 00:00:23,298 Now let's go ahead and represent an address book with another class. 6 00:00:23,298 --> 00:00:29,879 So once again, do New File, and we'll call this address_book.rb. 7 00:00:34,098 --> 00:00:36,310 And this will be an address book class. 8 00:00:38,620 --> 00:00:42,660 Now just like we did with our contacts, having addresses and 9 00:00:42,660 --> 00:00:46,900 phone numbers, when we initialize an address book class, 10 00:00:50,330 --> 00:00:53,250 we'll have our contact be an empty array. 11 00:00:53,250 --> 00:00:56,895 And that's gonna be an instance variable. 12 00:00:56,895 --> 00:00:59,944 So any method in address book is going to have access to it. 13 00:01:02,064 --> 00:01:06,990 Now, so that we don't have to use the at sign each time 14 00:01:06,990 --> 00:01:09,945 we want to refer to the contact, 15 00:01:09,945 --> 00:01:14,911 we'll say we have an attribute reader for contacts. 16 00:01:14,911 --> 00:01:20,474 And let's go ahead and create a method to print our contact list, 17 00:01:20,474 --> 00:01:24,838 and then we can just iterate through the contacts. 18 00:01:32,118 --> 00:01:38,720 And we'll print out our contact, and we can use the last name, first name format. 19 00:01:42,220 --> 00:01:45,320 So now that we have the address book class set up, 20 00:01:48,750 --> 00:01:52,860 we can instantiate one, and then let's go ahead and add a contact to it. 21 00:01:55,630 --> 00:01:59,758 And actually I think I can just grab this from our contact file. 22 00:02:02,078 --> 00:02:08,318 I'm gonna copy that, And paste it, and then I can take it out of here, 23 00:02:13,019 --> 00:02:16,839 So that it's not cluttering up the output like we had before. 24 00:02:20,619 --> 00:02:24,624 So now we can say address_book.contacts, and 25 00:02:24,624 --> 00:02:28,439 we will add this contact that we just created. 26 00:02:33,799 --> 00:02:36,398 And now we can print the contact list as well. 27 00:02:39,019 --> 00:02:42,078 And let's just say Contact List. 28 00:02:44,919 --> 00:02:52,230 Okay, now let's run address_book.rb, and this is not gonna work correctly. 29 00:02:52,230 --> 00:02:52,940 Can you guess why? 30 00:02:54,720 --> 00:02:59,180 And here we get the message uninitialized constant Contact. 31 00:03:00,460 --> 00:03:06,250 And the reason is we haven't told Ruby that we're gonna be using that class. 32 00:03:06,250 --> 00:03:10,060 So we have to do it the same way that we did in the contact class where we require 33 00:03:10,060 --> 00:03:11,409 phone numbers and addresses. 34 00:03:12,800 --> 00:03:18,899 We have to tell our address book, To require contacts. 35 00:03:21,578 --> 00:03:25,139 So let me clear my screen here and print this again. 36 00:03:25,139 --> 00:03:27,730 And hey, here we go. 37 00:03:27,730 --> 00:03:30,329 Our contact list now has my name on it. 38 00:03:33,049 --> 00:03:37,209 And go ahead and just add another contact. 39 00:03:42,208 --> 00:03:44,149 Just to make sure it all prints correctly. 40 00:04:18,586 --> 00:04:19,720 Okay. And one more time. 41 00:04:21,640 --> 00:04:22,370 All right. 42 00:04:22,370 --> 00:04:24,980 So far, our contact list is looking pretty good.