1 00:00:00,410 --> 00:00:05,040 Now that we know how to create and send in attributes when working on a class, 2 00:00:05,040 --> 00:00:09,930 let's go ahead and fix up our name class with the different name attributes. 3 00:00:11,450 --> 00:00:13,830 Now this pattern that we see right here, 4 00:00:13,830 --> 00:00:19,620 where we are setting instance variables, and then calling them later. 5 00:00:19,620 --> 00:00:22,240 It's something that's done quite a bit in Ruby. 6 00:00:22,240 --> 00:00:27,150 And Ruby actually gives us a shortcut for doing this exact thing. 7 00:00:28,420 --> 00:00:35,990 The shortcut is using a method called attr_reader which stands for 8 00:00:35,990 --> 00:00:37,860 attribute reader. 9 00:00:37,860 --> 00:00:39,020 Now let's try it right here. 10 00:00:41,000 --> 00:00:44,210 When we set the attribute reader as a title, 11 00:00:45,680 --> 00:00:49,100 we can go down to the Title Method and take this out. 12 00:00:50,830 --> 00:00:54,510 Now, if we run this program again, we should see the same thing printed. 13 00:00:57,030 --> 00:00:58,560 And we do. 14 00:00:58,560 --> 00:01:01,650 When we call the attr_reader method, 15 00:01:01,650 --> 00:01:05,760 Ruby is actually writing this method for us. 16 00:01:05,760 --> 00:01:07,680 It takes the name that we send in. 17 00:01:07,680 --> 00:01:08,910 Which in this case is title. 18 00:01:10,340 --> 00:01:13,830 And actually creates this method. 19 00:01:13,830 --> 00:01:16,410 Which just returns the variable. 20 00:01:18,500 --> 00:01:23,690 So we can go ahead and do that for all of our different named attributes. 21 00:01:33,260 --> 00:01:35,110 Now our class just looks like this. 22 00:01:37,870 --> 00:01:38,510 And let's go ahead and 23 00:01:38,510 --> 00:01:42,070 run it and just make sure that everything is printed out the same way again. 24 00:01:43,280 --> 00:01:45,910 And it works exactly as we expect it to.