because no one ever talks about active support. Everyone wants to talk about the crazy project, but let's talk about the project that we use every day. But let's talk about something else first. This is my badge, and that's my crotch. Sorry about that. I just wanted to inform everyone, ignore this. Ignore this. My name is B-R-Y-A-N, space L-I. Oh, pass. Sorry about that. So let's talk about active support. So here's the crazy thing about active support. Does anyone know of a library that was kind of like active support but existed before active support and still exists today? Passes. Yeah. Passes. The facets of Ruby. I've actually knew about the facets before. Rails even existed. And I think everyone here should dig into facets. It's at rubywork.github.com these days. So let's look at facets. So on the facets homepage, they give us this very interesting little word, and I'll read it for you. I usually don't do this, but trust me, it's funny. Ruby facets is the premier collection of general purpose, method extensions, and standard editions for the Ruby programming language. What does that mean? I don't translate it to you. I don't know what that makes me say. Really Ruby facets really is. Ruby facets is three things. There's a core Ruby facets library, and there's a whole bunch of neat little utility things that you can use to make Ruby even more fun to program. And actually that's the biggest thing about facets. They make Ruby more fun to program when they're not messing up the rest of your libraries because they stumble. They trample all over our page pages. But let's go into this and see what we've got going on. So one little neat thing that Bassist has is something called interpolate. So you just create a string, and let's call it hello, and inside there you can make a little interpolation here, and it does the same thing that it would do inside of ERB. Pretty simple, but I bet you didn't know that. Who here knew this, by the way? All right, I've taught someone, I've taught someone in every one of this room except for that guy, I'm from the living room. So here's another one, symbolized keys. Where have we seen symbolized keys? Where have we seen symbolized keys before? That's right. Where was it first? Actually, I don't know. I don't know. Take the hand of my hand, send it as contributor to this, and James Buck has contributed this, and I can support it, so I don't know. But there are some overlaps, and this is what I'm trying to show you. There is overlap. Just bugging your slide. There's a bug in my slide? Then it's the beat become the scene. It's matching. It's matching. It's matching. It's matching. It's matching. It's matching. And I'll let you guys know, there's no guarantee that anything you see on these slides is correct. I don't know if you've ever seen it, I've never seen it on my own. So moving on, we have UTC. We see much more familiar versions of this kind of stuff inside of active support, but you know what? You don't need it because it's already inside of facets if you choose to use it. And really what I'm here is just suggesting that there are alternatives to what you know, or what you used to. So we looked at the core library of facets, and then of course, there's a more library of facets, and it gets a little bit crazier. You can get random letters because everybody loves to generate random letters. And then there's something else that you've probably seen. Where have you seen this before? Active support. That's right, another active support. Similarity here. And you notice that you include memoizable, no namespace, no fastest namespace, so be careful when you use this stuff. So basically what this is doing for the uninitiated is, we are saying that we're going to include this module name memoizable, and we're memoizing this method A. So it only runs once in the implication of this class, or this object. So the third part of fast is something called on to work. I don't know why they call it this. They were trying to be funny. And inside of there, there was one interesting thing that I saw. There was a Y Combinator function in there. Who here knows how the Y Combinator works? I just put this slide up there because I thought it was a neat looking code. I have no idea how this works. So, why do we have facets? Well, we have facets. Or actually, I think. Oh, okay. Why do we use facets? Or why should facets go? Facts are good because there's a lot of code in here. And even if you don't choose to use any of it, all of us as developers should be reading lots of code. And there's lots of code in here to read. Take your lessons from it, whether it's good or bad, but at least you can read it. And make sure don't follow this. Use namespaces, please. So, active support. And support, support, suspenders, not the hammers. So let's talk about active support. And what I was trying to do here is there's some similarities between facets and active support. So, and all of David's wisdom, he put this blurb in like a reading file. Active support is a collection of utility classes and standard library extensions that were found useful for the Rails framework. These additions reside in the blah, blah, blah, and the blah, blah, blah, to a ruling on Rails. What is David really saying here? So really what we have here is, and what David was trying to say is back on February 15th, 2005, he realized that active support and our Active Record and Active Pack were actually starting to have a lot of similarities in them. And he said, well, you know what, let's create this thing called active support. And the cool thing is, I don't think there was any blog posts or anything, I actually just had to dig through this to find out where it was. And underneath here, whenever I release these slides, you'll notice that's the shot one on GitHub for the project or whenever it came to existence. I'm curious. So, what is active support? Active support is all this. What did they get right? They used namespaces. So, let's talk more about active support. I've been up here for seven minutes and 15 seconds, so I mean I have 23 more and I have 80 more slides. So, let's get started. So, I had to pick a small representative. Hello? This is weird. I'm used to having another mic, so. So, I'm used to having more time to talk about things, but I'm also used to being able to do things in more detail. So, what I'm gonna do for these six items is just glance over some of the cool things that I think are inside of active support. So, the first thing is assessors. What's the coolest thing about assessors? Anyone wanna take a gander at that? You knew it did you? No, I just had to throw a slide of beer in there. There's nothing cold out of assessors. But. But, let me tell you what, you get inside of active support. If you notice, if you use an assessor, assessors are usually only for like their instance levels. Rails is like, you know, like, we're better than that. We want assessors at our module and our class level. So, active support gives you this. And here's the assessor for at the instance level. And you notice that I find an assessor and then I instantiate a cow and I name the cow Clairebell. I like examples with cows as classes. So, you will see this a lot in this talk. So, what else can we do with this? So, at a module and a class level, once again, you can just use, I don't know if you call it matter assessor and cat or assessor. You can call it what you want, but same thing. And this is pretty simple. Anyone using this stuff in your code? Does anyone here not know about this? See, that's what I'm talking about. This is why I want to see more talks about code that we all use every day that we don't use. So, let's talk about something else, more assessor stuff. So, now we have, we have added assessor with default.  So, what you can do is you're gonna find an adder assessor with defaults and you can find the name and you can define what the default value should be. So, as my example goes, I defined it, I instantiated it and then look at that. I didn't have to do anything, but it seems to work. If you're using Rails, don't get too excited. This is not worth the side-back of record. So, that's a caveat. So, moving on to benchmarks, all right. So, we always want to see how fast our code is and a lot of us load up the benchmark, we just use benchmark and we call benchmark ourselves. But, inside of app support, they actually give you code that makes you do this very, very simply. So, what we have here in this instance is we've included this app support benchmark goal and then all you're doing is you're saying inside of this block, we're doing crazy fast stuff. I want you to do this and then tell me how fast it is. And you'll notice that I have a logger defined because it actually depends on the logger for your output. So, when you tell it to perform, we get doing crazy fast stuff. Where have you seen this before? Anytime you're looking at Rails ball file, this is actually how it works. I actually like this Google slide. You know how I'll test all the time is, this is gonna catch on, trust me. I'm gonna have everyone in here saying this. So, now we have callbacks.  A couple of months ago, I did a talk about active model and active model actually takes some big uses of lots. And so, let's look at this. So, what you wanna do is include access to our callbacks inside of your code. And we'll define a callback called synergize. Because you know, we always wanna synergize. So, when we synergize, we're going to actually put out the standard end, pivot complete. Because after I synergize, your pivot is complete. So, okay, now that we have our startup, let's make an instance of a daily deal startup. You might have heard this before. So, instead of, so now after we synergize and a daily deal startup, we're gonna retrieve more VC funds, because that's what we do. So, let's go through this stuff. So, we have daily deal startup and that inherits from a startup, because it is a startup of some sort. Less equal, or more equal. Then we send the callback to synergize. And then we say, after that, we synergize, we retrieve more VC funds. Anyone catch type code on this one? I think it should be a symbol. Like I said, I'm here to entertain. So, after we retrieve more VC funds, I got rid of the code where you do a soul selling and other stuff, because that's not important. So, now what we're going to do is take our new daily deal startup class, and we're gonna instantiate it, and we've got hot deals, and then we're gonna say, hot deals synergize, and we're gonna be like, pivot complete, bring on the billions. I know we've seen this before, and actually I actually typed in a Rails example of this. This is exactly how all the callbacks inside the Active Record work. I mean, this is it, exactly. I mean, there's a little bit of magic with Active Model, Rails 3 and whatnot, but what you're seeing here is this wrapped up nicely. Now you know how it works.  I've got problems. So, this is what I do when I'm not doing this. So, what we have here now is this is how I felt the day back in like 2006 or 2005-ish when I mastered, when I thought I mastered Mixins. And we all know what Mixins are, and I swear this slide right here will be the slide with the most amount of code on it. So, at a high level, what we're doing here is we're defining a mixin, and we're saying what is included to extend what we were included to the base with the class methods and include the instance methods. This is how a lot of your plugins work inside Rails. This is just how it works. So, now we have class methods and instance methods, but what you could have cat-spot was, this is way too much typing, so I only fixed it. And what I want right now is there was a slide on Saturday Night Live, and the guy who was Kenan Intel, is a Kenan, and it was after last year when we were having a halt of debt problems, and the first thing he was like, you identify the problem, then you fix it. And you want only five minutes doing this. So, Yehuda, identify the problem, like this, that's old school, okay. And you fixed it, and what they fixed it by is they actually created something called Concerns. I don't know if I would have called it a Concern, but that's what it's called. And really what we're doing here is we, I've created my module Smartacus, because I name this space, and then I have my module, new awesome feature, and it extends the Concern. And what it allows me to do is get rid of a lot of that boilerplate code. I don't need to be included anymore. Because as long as I follow the convention, I don't have to do the configuration. And where have we heard that before? What are you saying? So, I didn't do this on any of my other slides, but you'll notice that I actually required this five minute, and about 10 slides, I will tell you why I did that. So, we extended it, and then whenever we include this into our code, it'll do the same thing as this bad boy. But we don't need this crazy self-dot-included thing that no one, no people understand it, but a lot of people don't understand it. Moving on to configurable. And what I was trying to do is find a picture of something configurable, this is smart, we know. This is pretty configurable. Lots of stuff you can purchase off of it on there. So, let's talk about visa-backed support, but I don't understand why it's in there, I just wanted to show it to you guys, because it's in there, but I don't understand why anybody would use this. So, you can include something called act support configurable, and whenever you instantiate your new cow, you can actually now have a cow-dot config, and you can set a config variable in there, if you don't have to find it. I'm gonna go off on a sidebar, but for years, there's been something called open struct. You create something, if you create, you can actually create it as a read-only, and then assign it to, and when you initialize it, assign it to open structs. You don't need all the rest of that crazy act support configurable piece, but you know, it looks nice. So, maybe that's why it's in there. So, you can include act support configurable, and now you can do your config. There's a way you can do it where you can actually have, you can get rid of the dot config piece, and it would be cow dot utter count, but don't do that. So, next up is instrumentation. Anyone familiar with the instrumentation piece in Rails 3, act support 3? No one's using this? You're using it? You're familiar or using it? Using it. This is one of the coolest parts of Rails. So, with instrumentation, there's basically this, there's this, it gives you a, I guess you could call it a queue inside of Rails, but you can say, when something interesting happens, we can do this now. So, let's look at it. So, now we're going to subscribe. What we're telling act support to do is subscribe. This code is inside of this block to an event, whenever an event called milk comes, we're just going to put this event in an array called events, and we'll do something a little later. So, now we listen, now we'll learn. So, now what we're telling it to do is we're going to create a new cow, and then we're going to hit options as time, we're milking this cow now, and then we tell act support notifications to instrument this piece where we are milking, and we just pass the options along. And what we get here is inside of our events hash, now when we listen, when we're listening, we'll get these events, and it's just a hash, I mean it's just an array, so I can just say event name, duration, and payload. This is very simple, this is a very, very simple implementation, and actually there's like other fan out and other crazy queueer ones, but this is an easy way to do a implementation inside of any app. You can be doing this in your Rails app today. I know a lot of you guys use New Relic, but they don't think they do it this way, but they should be, because it's making these other Rails now. So, where does this leave us? And this is another issue that we, this is my, actually this is the reason why I wanted to do this presentation, because I learned about a cool feature of act support three, where if you're using act support two and you wanted to use it inside of an app that wasn't Rails, you actually have to include the whole entire thing in it. And what it kind of did is the major app looked like this. So you would have an app that might have 25 lines, but because you wanted to use time, you wanted to use like one of the fancy five days ago, you now have a process that's taking up all these megabytes of memory. But now, with Rails three, we don't have this problem anymore. What you can do is you can require act support and it'll require the whole entire thing. Or you can go and ensure you pick the pieces that you want. So if you only want the notifications framework, you can get this. You only want the callback framework, you can only get the callback framework. Pretty simple, right? I am here to entertain. So, this is what happens when you don't read. You don't understand how long you're gonna need to give a presentation so you can make a 20 minute one, because a lot of conferences only do 20 minutes and then you're supposed to get five minutes for talking in there. So, I created a 20 minute one. And thank you guys. Thank you guys for sitting. I don't see a lot of talks on just code anymore. And this is no offense to anyone in this room who might be doing this today. People want to talk about their new fancy projects. I want to talk about a project that everyone uses all the time and knows nothing about. So, what I did today is I explained to you guys, I probably taught you maybe seven things that you probably will never try, but we should all talk about them now. So, thank you. So, any questions? Any questions? What else? About what? Well, I'll tell you what happened last night when I was driving along. I won't tell you that. Yes? Is the instrumentation being used in Rails, I-Rails, or like, why is it there? Yes. Why is it there? I don't know. When I was doing the research for this, I actually, I did git clone Rails, or git clone git colon slash slash Rails, blah blah blah. And I did cd active underscore support. And that's where I stayed. I don't know if Rails uses it. But I think they do use it, I just can't tell you how. I didn't know they use it though. Any other questions? This is a RubyConf, man. In fact, change. Have you ever used facets in a project? Yes, actually I have used facets in a project. Since Rails? Yes, since Rails. So, this is how I know about the whole namespace issue. Before active support became very robust, back about 2008, we tried to use facets. What we would always find is that, depending on what order you required things, was depending on how your app would work. So, like you say, select the symbolized keys for hash, that is an active support now. If you have facets in there, which version do you get? So don't use them both together at the same time. That's why there are, there are some overlap between the two projects. But I do suggest that you go look at it just to see how in a different kind of style of how it all works. We're going to need more questions. It is 12.57. Thank you guys. Thanks. Thanks.