The Case of the Missing Method
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Subtitle |
| |
Title of Series | ||
Number of Parts | 66 | |
Author | ||
Contributors | ||
License | CC Attribution 3.0 Unported: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor. | |
Identifiers | 10.5446/46622 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
Ruby Conference 201814 / 66
5
10
13
14
17
18
21
22
26
29
37
45
46
48
50
51
53
54
55
59
60
61
63
65
00:00
CASE <Informatik>VideoconferencingMusical ensembleJSONXMLUML
00:34
Computer fileCASE <Informatik>Process (computing)Source codeProduct (business)Data managementIdentity managementSoftware developerSoftwareProgramming languageSoftware bug
01:50
Instance (computer science)Social classObject (grammar)Social classCodeInstance (computer science)Type theoryCuboidTable (information)Multiplication signSeries (mathematics)Inheritance (object-oriented programming)Ring (mathematics)CurvatureOffice suiteWritingCartesian coordinate systemStructural loadLevel (video gaming)FrustrationSoftware developerData miningChainSoftware testingProcess (computing)Point (geometry)Information technology consultingBeat (acoustics)Saddle pointInformation privacy
07:31
Network topologyObject (grammar)Kernel (computing)Module (mathematics)Instance (computer science)SpacetimeNetwork topologyObject (grammar)Social classInformationCausalityMultiplication signTheory of relativityTouchscreenModule (mathematics)Structural loadInformation privacyPoint (geometry)Parameter (computer programming)Computer animation
09:59
SpacetimeObject (grammar)SpacetimeObject (grammar)Ring (mathematics)NumberType theoryMultiplication signBitCausalityImage resolutionSocial classInteractive televisionCountingSymbol tableMessage passingControl flowComputer animation
11:33
Online chatComputer programmingPolygonJava appletModule (mathematics)Social classObject (grammar)Kernel (computing)Inheritance (object-oriented programming)Multiplication signSocial classFormal languagePolygonPhysical systemMeta elementComputer programmingObject (grammar)Electronic mailing listWordClosed setSpacetimeTouchscreenMoment (mathematics)ConcentricCodeModule (mathematics)Inheritance (object-oriented programming)Network topologyObject-oriented programming
15:20
Point (geometry)Formal languageMoment (mathematics)Ring (mathematics)Computer animation
16:17
Social classClient (computing)Social classDemosceneInstance (computer science)Software developerData miningObject (grammar)
17:21
Menu (computing)Inheritance (object-oriented programming)Social classCodeDifferent (Kate Ryan album)Block (periodic table)Software developerThresholding (image processing)Multiplication signData storage deviceSoftwareDeclarative programmingProblemorientierte ProgrammierspracheInstance (computer science)InformationCategory of beingVirtual machineComputer clusterRevision controlElectronic mailing listExistenceComplex (psychology)outputLevel (video gaming)Similarity (geometry)Object (grammar)2 (number)Social classPoint (geometry)Software testingBit rateParameter (computer programming)Interface (computing)Software frameworkSoftware bugQuicksortIdentity managementSystem callProcess (computing)Attribute grammarCodeEndliche ModelltheorieVariable (mathematics)Theory of relativityCAN busBitArtificial neural networkNeuroinformatikFocus (optics)Product (business)DemosceneStructural loadComputer animation
23:34
Social classHuman migrationFormal languageNumbering schemeRow (database)Electronic visual displayUniform resource locatorDigital photographyTexture mappingCore dumpModule (mathematics)DebuggerDisk read-and-write headRight angleRippingSocial classProduct (business)Goodness of fitDemosceneSoftware developerMultiplication signRootCodeDomain nameComputer fileObject (grammar)Power (physics)Projective planeSoftware bugConfidence intervalFormal languageArmData conversionLatent heatMereologyElectronic program guideSuite (music)HierarchyTable (information)Mobile appRow (database)Error messageSheaf (mathematics)Level (video gaming)Process (computing)Physical systemWebsiteHuman migrationInstance (computer science)Rule of inferencePoint (geometry)Context awarenessDifferent (Kate Ryan album)RoutingComputer animation
29:47
Social classComplex (psychology)Cartesian coordinate systemObject (grammar)FreewareWritingSoftware frameworkComputer animation
31:14
Core dumpPattern languageObject (grammar)Social classNormal (geometry)Consistency
31:49
MathematicsInstance (computer science)Social classInstance (computer science)Object (grammar)Computer animation
32:15
Social classMereologyCausalityLevel (video gaming)Multiplication signComputer animation
33:32
Crash (computing)XMLComputer animation
Transcript: English(auto-generated)
00:01
Thanks for coming to my talk. And I'm going to tell you a story today. You've come to
00:23
hear about the case of the missing method. But before I get started, I've got a question for you. Do you have a side gig? You know, something that brings in a little extra each month. I do. By day, I'm a product manager for a software team in a bank. But
00:45
by night, I'm a private investigator. And what is it I investigate? Ruby crimes. Not jewel theft. The programming language. And why did I decide to go into private
01:03
investigating? Well, there's been rumors of a shady mastermind who's been causing havoc and confusion amongst Ruby developers worldwide with his constant meddling in the source code. And I wanted to help put a stop to it. But I couldn't do this job
01:21
under my normal name. Right? I had to protect my identity. And so I chose the name Deidre Bug. D for short. And why did I choose this name? Well, for the sole purpose of making this joke. And today I'm going to tell you about one
01:43
of my more memorable cases. The case of the missing method. Chapter one. So, I was sitting alone, bored in my office. Well, I like to call it my office, but it's really just my flat. When the doorbell rings. And it's Mike. And he doesn't
02:03
look too happy. Let me tell you about Mike. So, he was an acquaintance of mine. We saw each other now and again. He was 24 years old. A junior Ruby developer. And he got excited about test-driven development. And he had been applying for an apprenticeship
02:24
at the prestigious Ruby Institute of Professionals. And he managed to get through all of the stages, beating hundreds of applicants to the final stage. And it was happening in two days. And there were two people left fighting for this final spot. Himself and
02:44
a woman named Jenny. Let me tell you about Jenny. So, she was 27 years old. Also a junior Ruby developer. And she loved all things Rails. She's also Mike's best friend and housemate. They had quit their consulting jobs at the same time to enter
03:04
the world of tech. And not long after, they also decided to live together. And so, for these interviews, they had agreed to work together to prepare so that they each had the best shot. May the best person win, they had said. And so, for this interview,
03:23
this final stage, they had been asked to research a series of topics that they were going to be grilled on. And one of them was method lookup. And they had assigned this topic to Jenny. And here was the reason that Mike had come to me. Something doesn't add up in Jenny's notes, he said. But Jenny's been so stressed and panicked
03:47
rather uncharacteristically that she won't hear me out, he said. She's convinced that she's right and she's saying that we don't have time for my doubts. But you can help me find the answer to this mystery. And he says that then he'll have what he
04:05
needs to confidently correct Jenny's notes and save them both from interview failure. So, he reaches into his saddle and he draws out some sheets of paper. And they're Jenny's supposedly flawed notes. I asked him to walk me through them. So, Jenny had
04:23
these boxes to represent the concept of a Ruby object. And all of these objects had a label called class. And this acted as a reference to the parent class of the object in question. So, some of these objects were instance objects. And the class label for these referred
04:41
to another Ruby object of type class. Class objects also had their own class label. And all objects of type class also had a methods label. And this pointed to a table of all the methods that instances of that class could call. And then Jenny had written, any
05:02
class you define is an instance of a class object called class. So, if we were to write class cake in our code, we're creating a class object named cake. It's an instance of another class object. And the name of that object is class. So, all classes
05:20
are of type class with a capital C. And then Jenny had this code in her notes. So, it was class cake. And there were two methods. There was one instance method called tasty, which returned true if the flavor of the cake in question was carrot. So, I immediately knew Jenny was smart. She was clever. And then there was a class method called
05:43
edible which always returned true. Okay. Then she wrote, imagine we had a cake instance called carrot. So, she had carrot equals cake.new. Then this is what the method look up chain would look like. So, she had one of her boxes and she labeled it carrot. It
06:01
had a class label. It pointed to another one of the Ruby object boxes and it was called cake that had its own class label. It also had a methods label which pointed to a table and there was a single entry, the tasty method. Because all instances of cake could call tasty. And then the class label for the cake object pointed
06:20
to another object labeled class with a capital C. And it had a methods label and that pointed to a table also with a single entry called edible. And then Jenny had written, a method definition always comes from an object's class. And at this point, Mike shook his head with frustration. It cannot be that the edible method lives on the parent class
06:44
for all classes, he said. Can I show you something, he asked. Can I jump on your computer? I said okay. So, he goes over to my desk, opens up terminal, enters pry and he loads in this cake class from Jenny's notes. So, then he shows that the class of cake
07:01
is indeed class and then he searches all of the instance methods for edible in class. Nothing. What a mystery. I am stumped at this point. And I'm just not sure how to proceed with this one. But if anyone can tackle a challenge like this, it's D. And besides,
07:23
this meant a lot to Mike. He was prepared to pay me handsomely. And so, I agreed to take on the case. Chapter 2. Ever heard of Google? Or if you care about your privacy or you don't like people on me spying on you, maybe you use DuckDuckGo. Well,
07:44
when I'm D, I don't believe in these tools, no. I don't trust them. And it's no coincidence that with this approach, I've become the best Ruby PI that industry has to offer. And so, what did I have? Books, books, and more books. And I spent a whole day
08:03
quickly skimming a load of books, but I couldn't find any useful information. So, I thought, well, why don't I form a hypothesis and go from there? So, I said, okay, the editable method, while not on the cake object, it must be somewhere in the ancestry
08:21
tree. So, what's the ancestry tree? Well, it shows all of the classes and modules that a class inherits from. So, all the possible places that a method could come from when you call a method on an object. And I thought, well, how do I search this ancestry tree? So, I made a method called where. And it took two parameters. An object
08:44
and a method. And that's the method that you're trying to search for in relation to the object. And I looked through the ancestors of the object's class to try and find the class where the instance methods of that class and only that class included
09:01
the method I was looking for. So, I thought, let me just check that this method's working. So, I created an instance of cake. And I said, let me find the tasty method on this instance carrot. And if it's working, it should be on cake. Great. Now it's time to find the editable method. It has to be somewhere in the ancestry tree. What?
09:27
Nowhere? At all? God, what a mystery. And at this point, I am confused. And I think, okay, it's time for some fresh air, it's time for a change of scenery. And so, I
09:40
decide to go to my favorite co-working space. And here I feel at home. Because I'm surrounded by people hacking away. And I quickly settle down at one desk. Given my naturally inquisitive nature, my eyes couldn't help but stray to the screen of the guy next to me. And he was playing around with this thing called
10:01
object space in IRB. And I asked him, I said, what's that? That looks interesting. And he said, well, it's a way that you can interact with all of the live objects within a Ruby session. So, if you were to type in object space.count objects and pass in the symbol T class, you can count all of the live class objects that
10:21
you have in a Ruby session. So, I thought, okay, it's probably time for a break. Let me have a play by myself in IRB. So, I went into IRB and I did what the guy had shown me. I counted up all the class objects. 936. So, I thought, okay, let me create a class and see that that number goes up to 937. 938? What?
10:47
Okay. Let me try that again. 940? What a mystery. But I don't have too
11:04
much time to think about this. Because just then my phone rings. And it's my friend wondering where I am. So, you see, I completely forgotten that I'd agreed to go to this tech lecture with her. And I was anxious that I really didn't have much time to solve Mike's case. But I'd been cancelling a
11:22
lot on this friend lately, putting my investigative duties first. And I thought that maybe on this occasion I should make a little bit of time for her. So, I rushed out of the door. Chapter three. So, I arrived just in time for the beginning of the lecture. And it was about a language called
11:41
small talk. I wasn't interested at all. I mean, I only have space in my heart for Ruby. But as I said, I was there for my friends. So, and the lecture was talking about how small talk had been born in the 1970s and it had led to the creation of object oriented programming. But it wasn't long before I couldn't concentrate. I couldn't stop thinking
12:03
about my play with object space. Each time I'd been creating one class, but yet two objects were being created. Pay attention, my friend said. So, I looked up to see the lecturer asking the room, what is
12:21
the class of a class in small talk? And she had this code on the screen. And I hadn't been following, but I could see that she'd printed out this polygon object. And then she'd asked the system that she was interacting with, well, what's the class of the polygon object? And it had returned polygon class. And then she typed in polygon class class. And it printed out meta class.
12:45
And she said, the class of a class in small talk is called a meta class. And then she went on to say that all languages that have been inspired by small talk have their own concept of meta classes. And that included objective C, Java, Python, Ruby,
13:02
Ruby. Oh. Something clicked. One class, two objects. So, I made my apologies to my soon-to-be no longer friend. And I rushed out of the door and ran home. And I thought, okay, let me try my luck. Okay. Of course that was gonna be too easy.
13:23
So, I said, well, let me look at all the methods that exist on Cake. So, I found this list rather overwhelming. So, I thought, how can I filter it down? Let me look at all the methods that include the word class. Okay. So, this list was
13:42
a lot more manageable. And two methods stuck out for me. One was superclass and the other one was singleton class. Okay. So, I thought, well, let me remind myself of the ancestry tree for Cake. And I said to myself, I know that the edible method already doesn't live on any of these classes or modules. So, then I thought, well, let's see what
14:02
superclass gives me. Object. So, I immediately knew superclass was not what I was looking for. Object was in Cake classes ancestors. So, that was time to try singleton class. Oh, this was new. Hadn't seen this before. Looked rather
14:21
strange. And when I looked at the ancestry tree, I saw three new classes that I hadn't seen before that looked rather different. Very interesting. And so, I thought, well, why don't I go back to my where method? And this time, rather than searching the ancestors of the
14:41
object class, why don't I search the ancestors of an object singleton class? So, I could search through those three new things that I just discovered. And then it was time to give it a go. Moment of truth. There was that thing. And I thought, okay, let me
15:01
just check that what I think is happening is actually happening. And in my excitement, I forgot how to type. But, I got there eventually and I confirmed that the edible method lived on Cake's singleton class. Case closed. Chapter four. So, at this point, I am
15:24
delighted. I'm so happy. And I'm really excited to share this news with Mike. I also took a moment to wonder whether I should retire. Because this would prove to be one of the biggest successes of my career. And they always say that you should quit when you're ahead. Anyway, I pushed those thoughts
15:43
aside. And I picked up the phone and I gave Mike a call. And the phone rings for forever. And I'm about to lose hope at reading him when he finally answers. And I say, hey, can I come round? I've solved the case. And he's excited. He says, of course, come round. I'll have
16:01
the notes ready and waiting for you. But although the case was solved for Mike, I wasn't satisfied. Because I just discovered a whole new concept in the language that I hadn't heard of before. What are singleton classes? And so, instead of going directly to
16:22
Mike's, I took a detour to a friend of mine. She was called Ellen. She was 43 years old. A freelance developer. And she regularly contributed to the case. And when I'm done, I ask her, what are
16:42
these singleton classes all about? And she says, well, they're hidden classes created internally behind the scenes in Ruby. And they're there to hold methods defined only for one particular object. So, take your instance of carrot, of the cake class. Its singleton class would hold methods specific to carrot only and not to any
17:01
other instance. Say if you had one called red velvet or chocolate. So, I said, okay. Given that they're working away behind the scenes, when does knowing about them become useful? So, Ellen thought for a while. And then she told me about one of her recent clients. They were called Budgeting Inc. And they were
17:23
a clever artificial intelligence machine learning personal finance tool for small business owners. And they were expanding globally. And they needed to roll out slightly unique versions of their software for each new city that they entered. Ellen told me how that when she first looked at the codebase, she
17:41
was horrified. Different developers had been responsible for each new city. And it looked like they were experimenting and trying out a new approach each time. Whether it was naming things, testing things, designing interfaces. And so, there was a lot of duplication in the codebase. And sometimes that duplication was very obvious. Like you could see it directly. And sometimes it wasn't
18:02
so obvious. It was hidden beneath the surface. But this meant that there was a lot of wasted time on development. Because the developers were often reinventing the wheel and they were often doing a bad job of it. And so, there were a lot of bugs. Some things had been copied hastily. Some things had been left out.
18:21
And it was really difficult to see what was important. So, the developers at the company weren't unhappy. They had a lot of tiresome, repetitive work and the cognitive load was really high. And the product owner was also unhappy. Because delivery was either very slow or things were spun up quickly and they were bug-ridden.
18:42
So, Ellen wasn't quite sure what to do. And then she said, well, I decided to create a DSL, a domain specific language. And she asked me if I knew what she was talking about. It's a mystery, Ellen. You're gonna have to explain. So, she said, well, let me show you what a basic version is. She beckoned me over to her computer. And she opened up Pry and
19:03
she input this class. So, it was called city instance. It had a class method called construct, which took a block. It then set up a city, a variable called city, which called that to initialize via the new keyword. Then we called instance of
19:20
AlanCity, passing in the block that we passed into the construct method. And then we returned the city object. There was an attribute reader called taxes. We then had an initialized method, which set up an instance variable called taxes as an empty array. And then we had a method called tax, which took an argument
19:41
called name. And that pushed the name of that tax into the taxes collection. And that was time to give it a go. So, Ellen created a city instance called New York. And she added a couple of taxes.
20:05
And then she printed out the taxes in New York. And so, she said, there we have it. That is a very simple DSL. And now we can quickly keep spinning up these lightweight city objects. So, imagine if we had other properties, though. Like a list of banks in a city or finance schemes. And
20:23
imagine if we had more information on each of these properties. So, maybe with the taxes, rather than just the name, we had some information about the threshold or the different rates. So, using this simple framework as a starting point, it's not hard to extend the city instance class to create incrementally more complex city objects. Well, imagine taking this to the
20:43
next level. Imagine interacting with the city instance class in the same way on the command line. But instead of just creating variables in our price session, we're spinning up new subclasses of city and other related models for each tax, scheme, bank that we list. So, Ellen explains that this was the
21:02
sort of thing that she had created for budgeting ink. A DSL that allows for quick, easy scaffolding of each new city subclass and any other related classes. So, she said, okay, I've shown you how you spin up identical city instances that have different names and different taxes. But what about if we
21:20
had one city that had a quirk? So, she asked me to think of a place in the UK, and I suggested Bath, since that was the case of my that was the scene of my first ever case. So, she said, okay, let's take Bath and let's add a tax. And then she said, can you think of something that makes people
21:40
in the UK really unhappy? And she didn't like my suggestion. She thought it was a bit too controversial. So, she said, well, let's focus on the fact that it rains all the time in the UK. And let's say the local government feels sorry for people, and so they clear all the taxes when it rains. Great. So, we looked at Bath's taxes, and then it rains. So, the
22:02
government's like, we'll call a rainy day out of the city. And then we look at the taxes again. No afternoon tea tax. Now, remember our friends in New York, Ellen said. Well, they've heard about this rainy day amnesty and they want some as well. And so,
22:21
it rains in New York and the government tries to call one. But no, undefined method of rainy day amnesty for city instance. And then there were these interesting characters after it. And Ellen said, well, what are these interesting characters? Let me show you something. And I saw that when she
22:40
called singleton class from New York, the exact same class object was returned. And so, Ellen said, when we enter the realm of DSLs and we're calling methods like instance of our, what we're doing is we're leveraging the existence of singleton classes. Because what instance of our does is it stores any method declarations that we pass into the class via the block argument
23:02
on an object singleton class. So, hold on to that thought, said Ellen. I just want to take a step back to the high level for one second. So, she says that by creating a DSL like this for budgeting ink, she enabled the developers to spin up each new city instance effortlessly. So, she explains how she had like abstracted away the key
23:22
similarities between any city. So now, the developers had a frictionless way via the command line of spinning up the foundation that they needed. And the code was way better maintained because all of the scaffolding had been tested once and tested by Ellen. So now, the developers didn't have to worry about it. They didn't have to touch it unless they changed
23:41
that code. Instead, they could now focus on the interesting parts. The customization that was required for each new city. The scope was much more refined. So now, the developers were happy because interacting with the system was a joy. It was easier to have a high level overview of the whole domain purely just by looking at the
24:00
documentation for the DSL. And the product owner was happy also because there were far fewer delivery was much faster. And she could also speak in the same language as the developers just by expressing new requirements in the terminology of the DSL. And now, let's go back to Singleton classes with Ellen.
24:22
So, why is knowing about them useful? Well, one of the main reasons I was able to complete this project to a high standard, said Ellen, was because I understood exactly where I was defining methods at any given time. She said that once you enter the realm of dynamically creating classes and methods on Singletons like
24:40
we did, well, and as you saw in your investigation, the class hierarchy and method look up gets far more interesting. And so, you might be getting error messages and you need to be able to spot where Singleton methods and classes are involved and where they're hiding. Because it can save you from a lot of headache. But beware, Ellen said. I've been going on and on about DSLs, but they're not
25:02
the answer to everything. If you have perhaps complex repeated business rules, and maybe you need to customize behavior in specific instances, then you can consider DSLs as an option. But even then, approach with caution. But, she said, you don't even need to be writing
25:22
DSLs for it to be beneficial for you to understand how they work. So, she asked me, you're using Rails, right? You're using it every day. Well, then you're seeing DSLs every day. And she went to the Rails guides website and she went to the active record migration section. And she said, well, look, these are carried out via DSL. When you call create table and you specify what each of the
25:41
columns are, that is a DSL. And she also said, when you specify how your Rails app handle HTTP requests, that's also done via DSL. And I thought, hmm, I've always just been doing this by rope. I never stopped to think about what was happening behind the scenes every time I typed the
26:00
resources keyword into my roots RB file. And there's more of these, said Ellen. So, she said that when people talk about Rails magic, it's not really Rails magic. It's more a collection of well-written DSLs. And then Ellen looked at me and she said, I hope you're TDDing all of the time. And I said, of course, Ellen.
26:22
What do you take me for? And she said, good. Because Arthbeck, with its described context, its blocks, that is all DSLs as well. And so with all of these Rails and Arthbeck DSLs that you're using every day, knowing about singleton classes can help. Because you might find yourself in the midst of a tricky problem.
26:42
And you can't make head or tail of it. Particularly if you inherit a code base. And so if you're seeing a funny bug to do with methods, you never know. Singleton classes might be the answer. And having them as part of your suite of debugging tools can be incredibly useful. So, I was feeling really leveled up by
27:03
the end of this conversation. And armed with this new knowledge, I headed over to Mike's. But when I arrived, I found a Mike who had tears in his eyes. He had obviously been recently crying. I looked down and I saw that he had crumpled pieces of paper in his hands. He raised
27:24
his arms towards me, offering me the papers. They looked exactly the same as the method lookup notes of Jenny's that he'd brought me the day before. So, I took the notes from him. I looked through them. I couldn't see what was wrong. They looked exactly the same. There was the carrot
27:41
object with its class label. That pointed to a cake object that had its class label. It also had its methods label with tasty in there. And the class object for cake pointed to the class object with its methods label, which also had the edible entry in there. But wait. It didn't say
28:03
class like last time. This time, it said cake singleton. And as Mike saw me notice this difference, he fell to his knees and broke down in tears. Jenny knew about singleton classes all along. He'd gone into her room to find the notes
28:21
in advance of my arrival, and this was the copy of the notes he'd found. Jenny was so desperate to secure the job for herself that she set out to intentionally mislead Mike in the hope that he would fail a whole section of the interview and therefore look unprepared. I, for one, was
28:41
disappointed in myself. I thank you. I have been, I know. I had been so focused on the main villain, the shady mastermind, that I'd failed to spot a villain right under my nose. My best friend tried to sabotage me. Mike cried. And at
29:01
this point, he started wailing again, saying he wasn't going to go to the RIP interview tomorrow. And I said, nonsense. You cannot give up now. I crouched down next to him. I gave him a comforting pat on the shoulder. And I said, you can do this. And I have just the thing to help set you apart from Jenny. And he looked
29:21
up hopeful. Have you heard of DSLs? I asked him. And I proceeded to tell him everything that Ellen had just shared with me. And although Mike still looked devastated as I left him, I had confidence that I had inspired him with the power of singleton classes, that he'd pull
29:41
himself together and go and secure the RIP internship for himself. So it's two months later, and I managed to drag myself out of the house to go to a hack night. And I'm just standing around, milling about, enjoying the free food and
30:00
drink, when I hear a couple of people whispering in the corner. Ooh, she's really famous, one of them says. And I look across the room, and who do I see? Ellen. So I walk over, we catch up, and I tell her that I've been reflecting on the case of the missing method. And I had my takeaways. So, you know, singleton classes,
30:21
they're there to hold methods defined for one particular object. And understanding them opens up a whole new world of Ruby. Because when you're dynamically creating classes and methods on the fly in more complex applications with things like DSLs, then it's really useful to understand them. I said to Ellen, I still feel as if day to day I can get
30:42
by ignoring singleton classes. So, do I really have to care about them at all? Not really, said Ellen. Well, like you say, if you're writing DSLs, then definitely yes, know what you're doing. And they do underpin popular frameworks, like I showed you,
31:00
like Rails. But day to day, you can get by ignoring them. However, she said, understanding why singleton classes are there, I think, is super interesting and empowering. Think of the Ruby core team. They wanted to keep things as straightforward and simple as possible. And
31:20
by simple, what I mean is they wanted to minimize special cases. Can we aim for having one way, one pattern for explaining how anything works in the language? They asked themselves, how consistent can we get things? So, let's think about consistency in the realm of Ruby methods. Well, if you think about
31:40
it, all methods in Ruby are defined in only one of two places. A normal class object or a singleton class. And every method in Ruby is really an instance method. And method lookup always starts with a singleton class. And class methods don't really have any fundamentally different behavior to other
32:03
methods. What we call class methods are really instance methods where the object in question is a class, and the method is stored on the class's singleton. So, yeah, singleton classes are invisible. But yet they're everywhere.
32:22
They're a fundamental part to how Ruby and its method lookup works. So, I left the hack night deep in thought. Ellen had inspired me to explore more of Ruby behind the scenes, because there was so much here that I didn't know. I'd only scratched the surface. And while I'd always been a
32:43
general Ruby PI, and I'd been very successful in the field, I thought maybe it was time to find a niche so that I could reach that next level.