 So, my name is Ted, I work in a company called Tinkerbox, and I'm here... Yeah, we have some Tinkerboxers here tonight. So I'm here to share with you five random Ruby tips. And I guess the fear when you do this talk is, since it's random right, what happens if you randomize the exact same tips as last time? So it's actually not completely random. True, true, true. All right, so let's go. The first tip is to unify and unfreeze your strings. So in Ruby 2.3 we got the frozen string literal pragma that allows you to freeze all your strings by default. And in addition to that we also got some new unary operators for strings. So you can actually do stuff like minus your string and it will freeze your string. We can do plus your string and it will unfreeze it. Now obviously you can't unfreeze things in Ruby, so it will actually just return you a mutable version of the string. And also important to point out that the minus works the same way. So you can't use the minus to freeze something in place like you would use the freeze method. So they actually work slightly differently. Now if you decide to do this just be careful because obviously the unary operators do somewhat different things if your variable is, say, fixed num. So just be wary of that. Okay, the second tip in the same flavor is to freeze your value objects or other things if you want to. So we have a hypothetical class here named point that takes some coordinates in its constructor and calling the freeze method inside the constructor. And there's obviously no magic going on here. The freeze method is defined in object and since point is an object you can just call it from wherever. Obviously to make your object immutable from the outside you can just use the readers, right? You don't have to use the assessor. I also define a method called nope to demonstrate that this will actually not work. So the nope method tries to update the x-coordinate of this point. But when you try to call it it gives you a runtime error and says that you can't modify your point because it's frozen. So this works on any object that you define yourself. The third tip is implicit to proc invocation. So most people by now know that you can pass a symbol to the ampersand operator when you're using an enumerator. And the way that works is by implicitly calling to proc on whatever you pass it. But this works on any object that you pass it, not only on symbols. So you can define to proc on anything you want. So in the example I defined to proc as a class method on our hypothetical point class. And it returns a proc. So if you are familiar with JavaScript this is similar to a function returning another function. In this case the function return just takes some arguments and instantiates a new point with those arguments. And this proc will actually keep its scope wherever it goes. So new will always refer to points new. And that could theoretically allow you to take some coordinates raw data that might come from an API or wherever. And instantiate point objects using a slightly shorter notation. So I listed three ways. The first way is probably the way that most people are familiar with and use. The second way uses the method method to get the method new from point. And that will also work because method implements to proc. And the last one is our example where we actually define to proc ourselves. So it's slightly shorter but if you want to do some convention like this it's important to remember that most people will probably not know what's going on. And if you don't know that to proc is called implicitly then it gets even hairier. But it is possible. Okay, first tip. The typecasting methods defined in kernel. So there are seven of them. Array complex float hash integer rational and string. And now you might ask what's going on here because these look like classes and they are also classes. Because it turns out in Ruby there's nothing preventing you from defining a class and a method with the same name. The only thing that will happen is you can't invoke your method without parentheses because it will return you the class instead. But this can be quite useful. So array for example if you pass nil to the array method it will give you an empty array and hash works similarly. And you have something like integer that works differently from calling to underscore i on your object as demonstrated here. So I have two strings that are sort of numbers but they also have some other stuff in there. So in the first example the string is one followed by a letter and two i will return one. The second one is a letter followed by a one and two i will return zero. So it's sort of inconsistent here. But if you try to call the integer method it will throw you an argument error. So for all of these methods they will return you what you expect or they will throw an error which can be useful in some cases. And of course because they are methods you can also use the method method to use them in a new level. Okay fifth and last tip and probably my favorite is the new squiggly hair dock. So if you don't know what hair dock is it's has been in Ruby for quite some time and it allows you to write long multi-line strings without messing too much with the interpreter. So hair dock is one of the things when I was reading the pickaxe book I was thinking okay I will probably never use this for anything because it seems weird. But the last few weeks I've been working a bit on RuboCop and I've actually found a valid use case there. This is the squiggly hair dock by the way. So they have this sort of declarative pattern matching language that they match to the AST and since you all know what an AST is now you can understand the merit of it. And here is an example of the dash hair dock which existed from before. So the slightly unexpected behavior here is that all these indentation spaces will be included in the string. But with the new squiggly hair dock all the leading spaces will be removed in the final string. And this was also introduced in Ruby 2.3 so you won't be able to use it. But I assume you all upgrade frequently and if you don't I think Winston wants to talk to you after. And those were the five random Ruby tips. Thank you.