1 00:00:00,000 --> 00:00:04,442 [MUSIC] 2 00:00:04,442 --> 00:00:09,780 Now that we have most of our classes set up, we can work on input and output. 3 00:00:09,780 --> 00:00:13,760 We're going to use a class from the Ruby Standard Library to save things between 4 00:00:13,760 --> 00:00:15,020 sessions. 5 00:00:15,020 --> 00:00:17,310 This is a lot easier than you think. 6 00:00:17,310 --> 00:00:20,150 Let's go ahead and see how that works now, using WorkSpaces. 7 00:00:21,500 --> 00:00:26,006 Okay, so we have our functionality with our address book working so far. 8 00:00:26,006 --> 00:00:27,893 We can add contacts. 9 00:00:27,893 --> 00:00:31,670 We can add phone numbers and addresses to our contacts. 10 00:00:31,670 --> 00:00:34,430 And then, we can go ahead and search through it if we want to. 11 00:00:35,720 --> 00:00:40,130 So now, we're going to make this more of a command line application. 12 00:00:40,130 --> 00:00:44,490 So what that means is we're going to have a menu 13 00:00:44,490 --> 00:00:49,160 allowing our user to select something and 14 00:00:49,160 --> 00:00:54,510 then work with it in the command line, rather than from inside of a Ruby file. 15 00:00:54,510 --> 00:00:59,410 Now the way that we're gonna do this is create a method that loops through, 16 00:00:59,410 --> 00:01:03,790 displays a menu and then will call each of these methods, 17 00:01:03,790 --> 00:01:07,180 depending on what the user enters. 18 00:01:07,180 --> 00:01:09,090 So let's go ahead and create that. 19 00:01:09,090 --> 00:01:12,232 Now, before we do that, let's go ahead and look at all this stuff down here. 20 00:01:12,232 --> 00:01:14,740 We're gonna just go ahead and get it out of there. 21 00:01:16,860 --> 00:01:20,880 So we have this address book that we initialize. 22 00:01:20,880 --> 00:01:29,300 And let's make a method called run which will display our menu on a loop. 23 00:01:29,300 --> 00:01:33,847 And that's all that we're gonna do to call 24 00:01:33,847 --> 00:01:38,660 this run method which will display our menu. 25 00:01:38,660 --> 00:01:40,235 So now let's go ahead and write that. 26 00:01:40,235 --> 00:01:47,351 Here is our run method. 27 00:01:47,351 --> 00:01:51,420 Now we're gonna use a loop, to display our menu. 28 00:01:52,690 --> 00:01:57,340 And we are going to need a way to exit the loop. 29 00:01:57,340 --> 00:01:58,750 But, we'll write that in just a second. 30 00:01:58,750 --> 00:02:03,650 So for right now let's just display address book. 31 00:02:03,650 --> 00:02:06,130 And let's go ahead and give an option here. 32 00:02:06,130 --> 00:02:11,470 If somebody enters the letter E they can exit. 33 00:02:11,470 --> 00:02:13,310 So we've got this little menu here. 34 00:02:13,310 --> 00:02:15,490 This is just the start of it. 35 00:02:15,490 --> 00:02:19,210 And then let's go ahead and ask for their input. 36 00:02:20,300 --> 00:02:23,580 We'll say, Enter your choice, 37 00:02:26,240 --> 00:02:30,690 and then we will grab the input and assign it to a variable. 38 00:02:30,690 --> 00:02:35,170 We'll use the getString method, which we'll just grab it from standard input. 39 00:02:35,170 --> 00:02:38,070 And that will go in with a new line. 40 00:02:38,070 --> 00:02:41,770 So we have to use the chomp method to get just the character 41 00:02:41,770 --> 00:02:42,690 that we're interested in. 42 00:02:43,790 --> 00:02:47,920 And then let's go ahead and just make that lower case so that when we search for 43 00:02:47,920 --> 00:02:48,640 it we know what's going on. 44 00:02:49,780 --> 00:02:53,540 Okay, now we know we're gonna add on to this later, so 45 00:02:53,540 --> 00:02:55,850 we're going to use a case statement right now. 46 00:02:55,850 --> 00:03:00,950 Since all we have is one option, we're just gonna have one single option 47 00:03:00,950 --> 00:03:06,650 in this case statement, so when the user types 48 00:03:08,050 --> 00:03:12,830 the letter E, we're gonna break out of this loop. 49 00:03:13,860 --> 00:03:16,201 Now let's go ahead and ruin this and see what happens. 50 00:03:20,920 --> 00:03:25,325 Address book, okay, let's type the letter e and make sure it exits. 51 00:03:25,325 --> 00:03:26,840 Uh-oh. 52 00:03:26,840 --> 00:03:29,340 Undefined method input for address book. 53 00:03:29,340 --> 00:03:32,390 I forgot an equals sign. 54 00:03:32,390 --> 00:03:34,480 Okay, let's clear the screen and run that again. 55 00:03:36,750 --> 00:03:38,340 Okay. Exiting works just fine. 56 00:03:38,340 --> 00:03:40,950 Let me clear the screen. 57 00:03:40,950 --> 00:03:43,260 We'll run this again. 58 00:03:43,260 --> 00:03:46,590 If I type a, okay we just get this menu again. 59 00:03:46,590 --> 00:03:49,020 DE2, whatever. 60 00:03:49,020 --> 00:03:49,590 Okay. Good. 61 00:03:51,170 --> 00:03:53,210 Now we know that E exits. 62 00:03:53,210 --> 00:03:56,430 This is a good start for our menu so we know that it's working.