1 00:00:01,150 --> 00:00:04,880 Okay, so we're got our say method, but let's go ahead and 2 00:00:04,880 --> 00:00:07,910 have our monster be able to do a few more things. 3 00:00:07,910 --> 00:00:12,300 And we're gonna store these things and count them and 4 00:00:12,300 --> 00:00:15,820 put a scoreboard on our monster later. 5 00:00:15,820 --> 00:00:19,960 So, we're just gonna say that our monster has some actions and 6 00:00:19,960 --> 00:00:21,460 when we initialize our monster, 7 00:00:21,460 --> 00:00:26,190 we're gonna keep track of these in an instance variable called actions. 8 00:00:27,280 --> 00:00:32,760 And we'll say that our monster, first off, can scream. 9 00:00:32,760 --> 00:00:34,050 Isn't that scary? 10 00:00:35,350 --> 00:00:41,080 And let's go ahead and make the actions an attribute reader as well. 11 00:00:43,540 --> 00:00:49,660 So now let's go ahead and define a scream method, and it's going to take a block. 12 00:00:52,230 --> 00:00:58,287 And we will yield to the block so that the block gets called, 13 00:00:58,287 --> 00:01:03,011 and let's go ahead and just print to the screen 14 00:01:03,011 --> 00:01:08,852 name, And screams. 15 00:01:10,665 --> 00:01:13,310 This method is almost done. 16 00:01:13,310 --> 00:01:17,460 First thing that we want to do, is increment 17 00:01:18,960 --> 00:01:23,770 the number of screams that our monster has done. 18 00:01:25,960 --> 00:01:28,040 So now let's go ahead and call this block, 19 00:01:32,691 --> 00:01:36,324 With our fresh new method, and 20 00:01:36,324 --> 00:01:42,170 we'll just go ahead and print BOO to the screen. 21 00:01:42,170 --> 00:01:44,160 That is pretty scary. 22 00:01:45,250 --> 00:01:48,796 Now let's go ahead and run this program, see what happens. 23 00:01:48,796 --> 00:01:52,290 Uh-oh, undefined method + for NilClass. 24 00:01:52,290 --> 00:01:54,250 Let's see what's going on here. 25 00:01:54,250 --> 00:01:57,714 That is on line 25. 26 00:01:59,840 --> 00:02:02,653 And, on line 17, 27 00:02:02,653 --> 00:02:07,620 undefined method + for NilClass. 28 00:02:08,890 --> 00:02:10,795 Let's see what's going on here. 29 00:02:10,795 --> 00:02:19,060 Oh, we had the wrong key that we were referencing. 30 00:02:19,060 --> 00:02:21,780 So now that we fixed that, let's run it again. 31 00:02:23,360 --> 00:02:26,150 Okay, Fluffy screams, BOO! 32 00:02:26,150 --> 00:02:29,690 Now let's go ahead and for now, just put to the screen 33 00:02:31,660 --> 00:02:34,580 the action counts here and see what happens. 34 00:02:36,870 --> 00:02:37,760 Okay, that makes sense. 35 00:02:37,760 --> 00:02:40,543 We have one scream, and that's what we thought. 36 00:02:43,937 --> 00:02:45,989 And let's just print it out beforehand too, so 37 00:02:45,989 --> 00:02:47,900 that we know that it's being incremented. 38 00:02:51,125 --> 00:02:56,437 But now when we call the scream method, we know that the block is executed and 39 00:02:56,437 --> 00:03:00,590 the number of screams in our internal hash is incremented. 40 00:03:02,590 --> 00:03:04,040 So, now that we know that that works, 41 00:03:04,040 --> 00:03:07,140 we can go ahead and create another couple actions here. 42 00:03:08,950 --> 00:03:12,590 Let's go ahead and create one for scares cuz that's what monsters do, 43 00:03:12,590 --> 00:03:14,040 they scare people. 44 00:03:16,030 --> 00:03:17,740 And, the scare method's gonna be the same thing. 45 00:03:24,482 --> 00:03:29,199 We'll go ahead and increment the number of scares. 46 00:03:29,199 --> 00:03:33,932 And then, We'll print 47 00:03:33,932 --> 00:03:37,970 that the monster has scared you and yield. 48 00:03:46,268 --> 00:03:48,340 So now we'll call it and make sure that that works. 49 00:03:50,930 --> 00:03:54,660 And our monster will scare you by saying, go away. 50 00:03:54,660 --> 00:03:57,455 That is pretty scary. 51 00:03:57,455 --> 00:04:00,080 So I'm going to clear my screen on the console down here, and run this again. 52 00:04:01,120 --> 00:04:01,710 Okay. 53 00:04:01,710 --> 00:04:06,960 That works, and the screams went from zero to one, and so did the scares. 54 00:04:08,140 --> 00:04:11,780 And everything is printed out just like we expect it to. 55 00:04:15,599 --> 00:04:17,340 Let's make a couple more methods here. 56 00:04:18,670 --> 00:04:20,700 One for run and one for hide. 57 00:04:22,919 --> 00:04:27,733 And I'm just gonna paste these in since they are pretty much exactly 58 00:04:27,733 --> 00:04:28,840 the same here. 59 00:04:30,000 --> 00:04:34,480 They are just like the scream and scare method. 60 00:04:34,480 --> 00:04:38,245 We also have run and hide, because those are two things that monsters can do. 61 00:04:43,066 --> 00:04:51,064 And now all we have to do is say monster.run. 62 00:04:54,031 --> 00:04:59,000 Monster is gonna say a scary thing when it runs and, 63 00:05:03,501 --> 00:05:07,230 Monster is also gonna say something very scary when it's running away and hiding. 64 00:05:08,770 --> 00:05:12,130 Now let's run this real quickly and see what happens. 65 00:05:12,130 --> 00:05:13,500 Uh-oh. 66 00:05:13,500 --> 00:05:18,890 It looks like undefined method + for NilClass, 67 00:05:18,890 --> 00:05:24,020 because we forgot to add these to the actions. 68 00:05:34,750 --> 00:05:37,977 Okay, let's go ahead and run this one more time, and 69 00:05:37,977 --> 00:05:40,860 it looks like that works just as we expect it to.