 Right. Good evening, everyone. My name is Monish. I work at a company called Money Smart and I'm here to talk to you about five random Ruby tips. The first one. There's a command called play minus L. This is a pry command. What it does for you is it runs a single line or multiple lines of code for you without you having to actually manually type each of these commands in a price session or copy paste them again from either a terminal, the price session or from your, say, code editor. And that's basically where it's mainly used for debugging faster because you don't have to do the manual work. If you want to see how this works, there are two ways I can show this to you. One is for a single line of code. So if you see it's play minus L and the line number and if I want to execute this for a range of lines of code, it's play minus L and the given range of lines. So let's just see how this works in action. I have an expenses application with me right now and I've already placed binding.py in my code. I'm going to calculate the expenses within a given date range. So let me just enter two random dates, say 1st of June 2017 to 29th August 2017. And I have a hit calculate total. Let's go to my terminal. If you see over here, this is the first binding.py. Just for the sake of continuity, I'll just type continue to show you another example where I want to execute the command. Let's say now I want to execute line number 67. So before that, let me see what is the value of from date. It's a string. And if I do play minus L line number 67, if you see the value of from date now, it's a date object. So it executes one line of code for me. Now let's say I want to do this for line number 70. But for my date validator, I see that I also needed to date. So I need to execute lines number 68, 69 and 70. How do I do that with play? So play minus L lines now line numbers 68 to 70. Before I do that, let me just show you what date validator currently has. So it should be nil. Yeah. All right. So play minus L 68 to 70. And so it returns true. So which is basically the final result of line number 70. Let's see if this actually has worked for us. So let's go to date validator. And if you see it has a from date has a to date. It's an object right now from a service called date validator. And this actually works for us. So this is the first command I want to talk to you about. So just to sum it up, you see that I don't have to manually type these commands myself. And I can debug faster this way. And it's the good thing about this. It's a very easy to remember command. The next thing I would like to talk to you about is another pry command. It's called disable pry. See if debug your problem. You're in the middle of a loop. The loop has got some complex logic. You don't know what exactly it's doing for you. You want to find out. So you put a binding dot pry in your loop. And say after one or two iterations, you have figured it out. I know how the logic works. And I don't want the binding pry to stop me from any more further iterations of the loop. I want to get out of it and just execute to the normal program flow. How do I do that? That's where this command is useful. And what it does internally is any further calls to pry will return nil. And the program flow will not be interrupted anymore. Let's see this in action. So for now, let me just go back to my application. If you see it's not calculated the expenses because we have not continued the price session. Let me just exit out of it. And you see that's a value. Now I'm just going to, for the sake of example, let me just add a loop. So I've just written a small snippet for it just for the sake of an example. I'm going to execute the same command for again a range of dates. I'm going to hit calculate total. Now you see I'm on line number 35. My binding plot pry has stopped over there. Let me just hit one continuous that we go within the loop. Now you see I'm with the loop. Well, this is a very simple example. And the loop is very simple. You know what it does for you. But let's just imagine that it was some complex logic. Let's just iterate through the loop at least once or twice. So you see it prints a value one prints a value two. Now I don't want to execute binding dot pry anymore within the loop. And say even any other binding dot pry within the rest of my action. So I just do disable pry. And you see that the program flow is not interpreted anymore. And that's where I can really use this command. This command comes with a catch. Before I explain that catch to you, let me just show you this again in execution. I'm going to take a two different dates this time. Instead of August, I'm going to give say July. And if I click on calculate total, you see it has given the value 9.7. But if you have observed closely, my pry session has not been stopped anymore. The loop has continued. So as soon as you give disabled pry, any further execution that you do will not actually stop pry from functioning for you as you see as per its natural behavior. Why is that? Because you need to go back to your code and manually enable pry again. There is a specific command that does that for you. I'm just going to type the snippet for that right now. So I'm adding that code back to my controller action. And I'm going to again give a range of dates. I'm going to hit the calculate total button. And if you see, it works again for us. So the actual thing that you need to do to enable pry again is online number 35. And after that, pry works for you normally. And yeah, that's basically how you can enable pry after doing a disabled pry. Cool. All right, let's get out of this faster. So, okay, I'll just leave the code here for now because in this example that I need to show you does not require me to go out. All right, the next comment that I want to talk to you about is a command that is used to clear the input buffer. So this is a command again, which is used again in the context of pry. The way this works is let's imagine you have a multi-line expression. I might make a typo in the multi-line expression. And for some reason, I want to fix that. Usually what happens is we do a control C, we try to stop the server, and we again go about, you know, fixing that because sometimes you just can't do it. You can't just terminate out of a loop without actually stopping the server. And you don't really want to stop the server for that. Is there another way to fix it? Yes, there is. That's where this command comes in handy. And yeah, it'll basically help you to clear the input buffer and you can type your multi-line expression within the same context without actually stopping the server. So yeah, let's see how this actually works for us. The example that I'm going to take is basically say I want to calculate odd numbers within a given range. And say I just type some code. Oops, I just realized I've given the logic to get me even numbers within the range. And say I want to fix this. How do I do that? So just exclamation mark will clear the input buffer for me. And I don't have to actually press control C or just stop my server. I again start typing the multi-line expression. I fix what I did wrong. And if I check my value of count, it's 3, which basically means we have 3 odd numbers within the range of 1 to 5. So this is basically how the command used to clear the input buffer is useful. Don't mistake this for the bank command in Ruby. It's not that. This is just something we use in the context of pry. All right. So moving on, the next thing I want to talk to you about is some of the aliases that I use in IRB RC. So this is one file which is configured with your IRB terminal. And I'm a little lazy. So just to say, if I want to exit from IRB, so I just simply just open it up and say if I want to require a specific file, I just instead of say if I want to require a library like factory girl, I can just give require factory girl. And it loads it for me. I don't type the whole command. So as programmers, we're lazy. So yeah, I just used some of the aliases there. One more alias that I want to show you is something used for say require relative. So RER and yeah, just the file. And yeah, it just runs the program for me. All right. One last thing is the alias to quit just press Q and yeah, I'm out of the IRB session. That's tip number four. The last tip that I want to talk to you about is so as programmers, we usually want to use certain defaults in our Rails applications. Say I want to use Postgres, but by default, I want to use aspect, for example, by choice. And I want to skip test unit and say, for instance, I also want to skip turbo links. We usually have type the whole command rails new new app name and skip test unit and all the other options that you want. So you get those defaults as part of a new Rails application. Turns out that there's a way to do it faster. And you don't have to really always remember these options whenever you create a new Rails application. So there's a file called dot Rails RC. And in that file, you can specify these options and in the home directory of your computer. And Rails will automatically pick up these options for you. And what it does is it basically will just get the defaults working for you in the app and you don't have to really remember these commands just for your information. And yeah, it again makes life easier. So I hope these commands help you in your day-to-day programming. Yeah, that's it. Thank you. Thank you so much. Thank you.