1 00:00:00,025 --> 00:00:05,099 [SOUND] Now that we know how to use arrays and hashes, 2 00:00:05,099 --> 00:00:12,180 let's write a simple program that uses everything we've used so far. 3 00:00:12,180 --> 00:00:15,388 We're going to do this over a few different videos, so 4 00:00:15,388 --> 00:00:17,919 be sure to follow along using workspaces. 5 00:00:18,980 --> 00:00:23,020 Okay, now that we know how to work with arrays and hashes, let's go ahead and 6 00:00:23,020 --> 00:00:25,200 write a simple shopping list program. 7 00:00:26,260 --> 00:00:30,310 So I've gone ahead and launched a new Ruby workspace. 8 00:00:30,310 --> 00:00:33,857 Now, let's go ahead and create a new file. 9 00:00:33,857 --> 00:00:38,470 And we'll call this shopping_list.rb. 10 00:00:38,470 --> 00:00:42,430 Now let's go ahead and create a shopping list. 11 00:00:42,430 --> 00:00:46,710 We'll create a method that asks for the name of the list, and then, 12 00:00:46,710 --> 00:00:52,780 we can return a hash of the name and the items inside of the shopping list. 13 00:00:54,080 --> 00:00:57,780 So we'll call that method, create list. 14 00:01:00,704 --> 00:01:03,774 Now let's go ahead and ask what the list's name is. 15 00:01:08,120 --> 00:01:13,283 And we will take from standard input, the name of the shopping list and 16 00:01:13,283 --> 00:01:19,500 remove any external characters from it that are white space at the end. 17 00:01:19,500 --> 00:01:22,707 Now let's go ahead and return a new hash. 18 00:01:26,712 --> 00:01:31,505 We will give the hash a key of name and a key of items. 19 00:01:34,500 --> 00:01:36,400 Which is a new array. 20 00:01:36,400 --> 00:01:39,260 And then, we'll go ahead and return this hash. 21 00:01:42,100 --> 00:01:46,194 Now that we have a method to create the list, let's go ahead and 22 00:01:46,194 --> 00:01:48,910 create a method to add an item to the list. 23 00:02:01,460 --> 00:02:03,610 So now we're going to add a list item, and 24 00:02:03,610 --> 00:02:06,015 we'll get the item name from standard input. 25 00:02:08,375 --> 00:02:13,820 And then we'll create a new hash, and we can return that hash. 26 00:02:15,760 --> 00:02:17,490 Go ahead and save that. 27 00:02:17,490 --> 00:02:21,410 And now, let's go ahead and ask the user. 28 00:02:21,410 --> 00:02:22,090 Or their list. 29 00:02:23,540 --> 00:02:28,069 So we can say, list and then an equals sign, and 30 00:02:28,069 --> 00:02:31,587 we'll call the method create list. 31 00:02:34,780 --> 00:02:39,808 Now what that will do is ask the user for the name of the shopping list, 32 00:02:39,808 --> 00:02:45,365 and return a hash with the key of name and the key of items, which is an array. 33 00:02:48,287 --> 00:02:53,000 And let's go ahead and print out list.inspect. 34 00:02:53,000 --> 00:02:56,260 Now let's click down in the console and run this shopping list program. 35 00:02:58,110 --> 00:03:00,480 The list name is Groceries. 36 00:03:01,790 --> 00:03:05,670 Now we can see we've got this list hash, 37 00:03:05,670 --> 00:03:10,050 with the name of what we input in an empty array for items. 38 00:03:11,330 --> 00:03:14,850 In the next video, we'll start adding items to the list.