1 00:00:00,670 --> 00:00:02,580 So we're done with our Monster program, 2 00:00:02,580 --> 00:00:07,910 but I wanted to show you something really cool that you can do with blocks. 3 00:00:07,910 --> 00:00:13,180 So, here we have our different actions and 4 00:00:13,180 --> 00:00:16,650 we're calling them within the context of a block. 5 00:00:16,650 --> 00:00:20,908 Let's just see what the last thing that we have here, okay, monster.hide. 6 00:00:20,908 --> 00:00:25,108 Let's go to this hide method, and we yield to the block, 7 00:00:25,108 --> 00:00:30,990 which means we're coming out of this method, and calling that block. 8 00:00:30,990 --> 00:00:34,710 So, it jumps from here, in this hide method, 9 00:00:34,710 --> 00:00:40,970 down to monster.hide, right here, and executes this block of code. 10 00:00:42,660 --> 00:00:48,390 Something that's kind of neat that we can do is yield arguments to the block. 11 00:00:48,390 --> 00:00:54,730 Now we know that from earlier lessons that we can provide arguments to the block. 12 00:00:54,730 --> 00:00:59,730 So, we'll just say if a block is given here, 13 00:00:59,730 --> 00:01:04,050 let's provide this argument and what argument would that be? 14 00:01:04,050 --> 00:01:08,960 Well, if wanted to we could provide the actions variable and 15 00:01:08,960 --> 00:01:12,060 then we would have access to that in the block, but 16 00:01:12,060 --> 00:01:16,360 let's do something a little more interesting and yield self. 17 00:01:18,050 --> 00:01:21,430 self is the instance of the monster. 18 00:01:23,020 --> 00:01:26,678 So we'll get the monster instance inside of the block. 19 00:01:26,678 --> 00:01:29,846 Which means, 20 00:01:33,001 --> 00:01:36,150 we could put this in as an argument called monster. 21 00:01:38,410 --> 00:01:43,760 And in here, we would have access to the monster variable. 22 00:01:43,760 --> 00:01:46,040 And actually, let's just put that in as m. 23 00:01:47,830 --> 00:01:53,183 And let's print out the actions here, just to see what it looks like. 24 00:01:58,002 --> 00:01:59,120 Printed out the scoreboard. 25 00:01:59,120 --> 00:02:00,010 Let's go back up. 26 00:02:01,040 --> 00:02:07,965 And this is pretty neat right here, screams, scares, runs, and hides. 27 00:02:07,965 --> 00:02:13,135 And let's go ahead and just prove that we can get access to all the methods in here. 28 00:02:13,135 --> 00:02:15,375 We define an inspect method. 29 00:02:19,855 --> 00:02:25,965 We'll just say inspect is the name and the actions. 30 00:02:32,198 --> 00:02:33,010 Clear my screen. 31 00:02:33,010 --> 00:02:33,950 Run this one more time. 32 00:02:36,890 --> 00:02:37,630 And here we go, 33 00:02:37,630 --> 00:02:43,260 we've implemented an inspect method that we call from inside of this block. 34 00:02:43,260 --> 00:02:46,610 This is not something you totally need to do, but it is pretty cool and 35 00:02:46,610 --> 00:02:49,330 something that you will see in Ruby programs.