00:00:04.740
okay hello everybody my name is Quincy
00:00:07.930
I'm a final year student from the
00:00:09.790
Singapore University of Technology and
00:00:11.170
design and I was introduced to the world
00:00:13.420
of Ruby and rails about slightly more
00:00:16.330
than a year ago so by way of a very
00:00:18.880
short self introduction this is my
00:00:21.550
exceedingly silly get up handle and this
00:00:25.029
may or may not be my typical facial
00:00:26.289
expression IRL
00:00:27.689
so my talk today is called all I wanted
00:00:31.449
to know about Ruby's object model
00:00:33.040
starting out and more but before I dive
00:00:37.960
into the topic proper I want to talk a
00:00:39.760
bit about the motivations behind it so
00:00:41.590
now why does hoppy again
00:00:43.030
why does talk well you asked me why this
00:00:46.300
talk the first thing I'm going to say to
00:00:47.739
you is free Rd are three tickets yay my
00:00:52.300
boss I also want to approach this mode
00:00:54.010
right now as a beginner who's got
00:00:55.960
minimal programming and the language and
00:00:57.760
software development in general so the
00:01:00.190
questions I have is what does it like to
00:01:02.800
be a beginner learning Ruby so in the
00:01:07.660
beginning everything is lovely and
00:01:09.520
beautiful right the language is clean
00:01:11.560
clutter free expresses sometimes even
00:01:13.720
reads just like English block talks
00:01:16.810
enumerators and numbers slightly strange
00:01:19.090
but you get the hang of it after a while
00:01:20.380
and the basic object-oriented paradigm
00:01:22.960
isn't too hard to pick up so pretty soon
00:01:25.030
your writing classes are crossing down
00:01:26.530
material modules and so you are in love
00:01:30.390
but if you hang around with Ruby long
00:01:32.890
enough you start to see some stuff like
00:01:36.549
this and this and you hear people
00:01:39.729
talking about singleton methods method
00:01:42.430
classes mixing and extending modules and
00:01:45.400
sales including them and so on and so
00:01:46.930
forth and a lot of hit scratching and
00:01:48.430
confusion ensues and maybe you keep
00:01:50.950
reading and rereading boovie Docs and
00:01:53.079
various blog posts but you still can't
00:01:55.149
quite know remember the difference
00:01:56.740
between start even instant evil or you
00:01:58.450
still keep wondering what whether that
00:01:59.799
self thought included hooks does thunder
00:02:01.329
or why'd you go necessary right and so
00:02:04.240
you begin to realize that you should be
00:02:05.680
able to do better you should be able to
00:02:08.049
build a mental model that has the power
00:02:10.060
of unifying or the seemingly disparate
00:02:12.550
bits of Ruby
00:02:13.360
and so there's why self to do and that
00:02:16.090
is basically all i want--is know about
00:02:17.600
these object models study out but
00:02:20.660
because I also have completionist
00:02:22.490
tendencies I decided to poke around the
00:02:24.620
see Ruby source code itself and that is
00:02:26.750
where the moor comes in so without
00:02:30.080
further ado here's all I wanted to know
00:02:32.750
about Ruby's object model starting out
00:02:34.940
as a story in the beginning there was
00:02:41.860
chaos but soon from the primordial soup
00:02:46.250
of proceeded Oracle the strong force
00:02:48.290
type deaths and macro and these
00:02:51.320
gradually coalesced into the finest of
00:02:53.480
all Ruby's and Ruby said let us make
00:02:57.350
objects but not in our image in our
00:02:59.630
likeness I am a jealous Ruby and I want
00:03:01.460
to be the shiniest Ruby there is and so
00:03:04.250
was wrought the planers of all objects
00:03:06.880
basic object a basic object new kernel
00:03:11.060
and unto them was conceived and born
00:03:13.310
object an object begotten module and
00:03:16.850
module D got class now Ruby had given
00:03:21.290
her creation dominant across the land
00:03:23.480
and so object set forth and begot many
00:03:26.720
other classes whose multitude of
00:03:28.880
concrete instances soon spread across
00:03:31.730
the code of the very many Ruby
00:03:33.230
programmers of the world and so this was
00:03:38.630
the world all the objects in you and it
00:03:40.700
was great and happy but Ruby had also
00:03:45.200
furnished her creations of a very
00:03:46.790
special kind of power which was soon to
00:03:49.760
precipitate a great and substantial
00:03:51.560
crisis this was the power of
00:03:55.330
introspection and so it was that one of
00:03:59.240
the first objects don't begin to ask
00:04:03.670
what am i and she discovered that he
00:04:07.340
could call the method class and the
00:04:10.130
answer was as plain as day he was a dog
00:04:12.110
and slowly as a central crisis passed
00:04:15.250
now the dog was happy but as what has it
00:04:19.780
dog now had a problem he asked the same
00:04:24.290
question what am i and so he called the
00:04:27.110
method class and discovered that what he
00:04:29.150
was was a class
00:04:30.930
and he discovered you could also call
00:04:32.910
the method superclass and remember that
00:04:35.639
his parents was none other than object
00:04:38.000
and so dog knew what he was and where he
00:04:41.460
came from and so he was content yet this
00:04:45.690
was not the end soon even the most
00:04:48.090
ancient of objects began questioning
00:04:50.039
their own existence basic object object
00:04:53.910
module class all of them asked what mi
00:04:58.680
and it turned out the awesome were
00:05:02.370
classes and they remembered whom had we
00:05:05.280
got who kernel asked herself the same
00:05:08.190
question and discovered that she was a
00:05:10.289
module and remembered that she had no
00:05:11.880
parents to speak of and so this was the
00:05:15.479
world that all the objects knew and some
00:05:17.550
of them thought the arrows were getting
00:05:18.870
a little bit messed up but Elizabeth
00:05:21.889
Allah the first wave of the existential
00:05:25.229
crisis was now over but soon enough dog
00:05:29.070
began agonizing again he complained to
00:05:31.830
dog you said it as a dog I should be
00:05:34.949
able to bark and rag my tail and we
00:05:37.139
stopped on my belly and so forth I know
00:05:39.690
I'm different from the other dog
00:05:41.310
instances I way different and so on but
00:05:43.560
truly I want more individuality than
00:05:46.110
that not just I want the means and the
00:05:49.050
methods to manifest my singly dog nature
00:05:52.310
not just bark but the goal so daughter
00:05:55.400
such Wow
00:05:57.680
and dog the persimmon shook his head
00:06:01.710
forcing you not what he could do but in
00:06:05.130
the night dog is visited by Ruby herself
00:06:07.800
who was full of sympathy for the poor
00:06:09.810
animal and so she spoke softly I do
00:06:12.960
grant you the power to be the Doge that
00:06:14.909
you want to be no longer shall you be a
00:06:17.400
dog but you shall be a singleton Doge
00:06:20.810
yet to keep the peace I cannot make this
00:06:23.490
obvious for if I do dot will be jealous
00:06:25.699
and so was created a new class the
00:06:30.599
singleton class of Doge but it was such
00:06:33.240
that if those caught the method class he
00:06:36.840
knew himself still as a dog it was only
00:06:39.450
if he called the method singleton class
00:06:41.070
that he knew where as uniquely those
00:06:42.900
abilities came from
00:06:45.380
only Ruby knew that deep in the
00:06:47.699
primordial chaos gorgeous true class was
00:06:50.580
actually his singleton class now
00:06:53.699
daughters happy but of course dogs now
00:06:57.030
had a problem he complained to Ruby the
00:07:00.810
programmers want me to keep track of all
00:07:03.330
my dog instances and find them by their
00:07:05.130
name I can't do that with normal
00:07:06.780
instance methods
00:07:07.740
I need class methods and Ruby
00:07:10.560
remembering what she had granted dog so
00:07:13.050
similar solution over here and so she
00:07:15.120
spoke softly I do granted the power to
00:07:17.280
his methods of your own and not methods
00:07:19.380
that all class objects possess and so we
00:07:24.509
created a singleton class of dog and
00:07:27.470
because dog himself was a class this
00:07:30.570
singleton class was like a class of a
00:07:32.610
class and Ruby christened it a meta
00:07:34.860
class to distinguish it from the normal
00:07:36.479
singleton classes of ordinary instance
00:07:38.220
objects like dodge but in creating the
00:07:41.340
dog singleton class Ruby now had to
00:07:43.349
create the class metal class and the
00:07:46.979
volume ethics class in the object
00:07:49.229
methods class and the basic object
00:07:51.270
method class and he made it such that
00:07:53.610
the original genealogy was mirrored so
00:07:55.620
it was SS the basic object metal class
00:07:57.479
that we got the object meta class and
00:07:59.220
the object method class had we got the
00:08:01.020
odd module metaclass and so on and
00:08:04.320
because we like arrow so she made it as
00:08:06.300
if class had be got the basic object
00:08:08.460
method class so now the objects in the
00:08:13.020
classes they were finally happy but now
00:08:15.330
their world has been very much
00:08:16.469
complicated and every so often one of
00:08:18.960
these method classes was wanted to cause
00:08:21.659
mischief
00:08:22.259
demanding that they have their own meta
00:08:24.419
class and these metal meta classes would
00:08:26.969
be even more mysterious demanding that
00:08:29.280
they have their own meta class and on
00:08:31.860
and on with these metal metal metal
00:08:33.390
metal classes go until no one could see
00:08:35.579
the end of the whole damn thing and all
00:08:37.770
the ordinary objects and classes just
00:08:39.930
roll their eyes and went onto the car
00:08:41.820
day to day
00:08:42.419
oblivious to all this metal madness and
00:08:47.670
so is that I have come to the end of my
00:08:49.440
Ruby creation myth so hopefully that was
00:08:53.400
able to give you a sort of dramatic
00:08:55.040
overview of Ruby's object model in a fun
00:08:58.079
way
00:08:58.880
and with that then it is time for floor
00:09:03.890
it is time to retell the Ruby creation
00:09:08.460
myth through the lens of see Ruby force
00:09:12.050
so as they say in Ruby all data is
00:09:15.840
represented as an object so gold is an
00:09:19.800
object and dog which is a class is also
00:09:22.260
an object and what this translates to in
00:09:25.110
the see ruby sauce is that all our
00:09:27.600
objects are represented as pointers to
00:09:29.370
struts so you have this point of this
00:09:31.890
arrow over here pointing to a very value
00:09:36.120
at a memory address in this case a value
00:09:37.560
is a struct which is a bag of attributes
00:09:39.360
also called them members now the
00:09:42.810
question of course is what is actually
00:09:44.490
in this struct and this is the point I'm
00:09:47.160
going to show you some actual C Ruby
00:09:48.270
code just to note this is from the 2.4
00:09:49.830
branch so there will be 3 strokes who
00:09:52.470
are primarily interested in the first is
00:09:54.750
the struct used to represent ordinary
00:09:56.820
instance objects our object second is
00:10:00.180
the struts used to represent class
00:10:01.770
objects our class and finally you'll
00:10:04.200
realize that both of these trucks
00:10:05.310
actually saw a third straw our basic so
00:10:09.540
let's take a look at our basic this is
00:10:12.450
the struct that sauce information that
00:10:13.830
is basic to all objects right so first
00:10:16.020
we have a Flags member which is
00:10:17.610
basically false metadata of object so
00:10:19.560
whether or not this is a instance object
00:10:21.630
or class object or model object all this
00:10:23.610
is stored in flags and also whether or
00:10:25.680
not this is a singleton class that is
00:10:27.360
also stored in flags secondly and very
00:10:30.630
importantly we have this class is the
00:10:32.280
k-member so this is actually a reference
00:10:33.960
to the class of our objects right so it
00:10:36.510
points to an our class struct and we
00:10:39.870
look at our objects well it's just our
00:10:41.700
basic class stuff plus our basic classes
00:10:44.220
unions thing over here which suffice to
00:10:45.900
say is for storing instance variables
00:10:48.240
and finally our class again we have our
00:10:54.810
basics so we also have slides on class
00:10:56.990
but importantly we also have this super
00:10:59.370
member which is a reference to the super
00:11:01.440
class of this class so it also points to
00:11:03.240
our class struct and then we have this
00:11:06.210
pointer to this something called a Ruby
00:11:08.160
class extension struct which we won't
00:11:09.570
worry about but I should mention that
00:11:11.430
since
00:11:12.030
objects are also instant objects they
00:11:13.830
also can have their instance variables
00:11:15.120
and these class instant variables I
00:11:16.950
actually sought in this class extension
00:11:18.360
struct finally we have a pointer to the
00:11:21.690
method table so this is where the
00:11:23.070
instance methods are start and this is
00:11:24.990
the table that's looked up during method
00:11:26.730
dispatch so we talked about method
00:11:30.120
dispatch this is the car you know logic
00:11:32.580
right here right in this search method
00:11:33.960
function basically lookup the method
00:11:36.660
table of my class and if I kind of find
00:11:38.250
anything just go out my inheritance
00:11:39.840
chain go out my super chain and keep
00:11:41.280
looking up the method tables until we
00:11:43.200
find a method with a matching me so if I
00:11:46.590
call the class method on Doge this will
00:11:50.610
be the chain of our class trucks whose
00:11:52.980
method tables will be looking up except
00:11:56.510
not quite there's a slight complication
00:11:58.530
here from Colonel which you realize it's
00:12:01.350
not a superclass of object it's just a
00:12:03.030
module that's mixed into object yet
00:12:06.030
somehow it manages to find its way into
00:12:08.070
this super chain over here and we'll see
00:12:10.290
more clearly how that happens when we
00:12:12.060
talk about modules later on so with that
00:12:16.920
we have laid the basic round you've seen
00:12:19.230
how ruby actually represents our data as
00:12:21.090
pointers to strut now the question is
00:12:23.220
where does it all begin where does our
00:12:25.590
Ruby creation miss actually start and
00:12:28.130
the answer is in this dryin function in
00:12:31.740
objective-c called init VM object and at
00:12:34.200
the very top you realize it's calling in
00:12:35.670
its class hierarchy now this is a
00:12:37.830
function where our class hierarchy
00:12:39.150
actually gets a bootstrapped right so
00:12:41.160
after all these Bhoots def class
00:12:42.480
function calls our hierarchy goes like
00:12:44.550
this and all these are basic set class
00:12:46.800
macro calls are basically setting the
00:12:48.810
class pointer of basic object object
00:12:51.630
module and class to point to class and
00:12:55.760
at this point may be like where is
00:12:58.080
colonel well if you go back to init VM
00:13:00.540
object which is a really gigantic
00:13:02.190
function but somewhere in there we are
00:13:04.290
initializing kernel and including it in
00:13:06.210
object and so at the end of all this
00:13:10.260
your diagram looks something like this
00:13:11.910
pretty much what we saw from the
00:13:13.380
creation mistress now in addition to
00:13:15.810
basic object object module and class and
00:13:18.480
kernel Ruby also initializes all the
00:13:20.550
built-in classes such as neo string
00:13:23.070
array true class and so forth
00:13:25.460
in it VM object so you're happy of that
00:13:28.640
but now the next interesting question is
00:13:31.000
what happens when I actually define my
00:13:33.649
own class so say I want to define a
00:13:36.620
class dog a key function that gets
00:13:40.010
called is RV define class ID and this
00:13:43.399
basically does three things the first is
00:13:46.670
if we don't specify our explicit super
00:13:48.890
we set a default super to object tree on
00:13:51.680
all right
00:13:52.270
second we actually create the new class
00:13:55.970
so we initialize a new art class struct
00:13:57.709
with the given super and this also sets
00:14:00.680
the class pointer of this our class
00:14:01.970
dropped to point to class with the
00:14:04.130
capital C and finally we actually make
00:14:08.300
and set the method class of this class
00:14:10.520
straight away so before we talk about
00:14:13.970
meta classes and all diagram looks like
00:14:16.220
this it's pretty simple we just created
00:14:18.560
a new class dog we said it's super we
00:14:20.779
set its class pointer okay by this is
00:14:22.970
default meta classes and before I want
00:14:25.640
to talk about meta class creation I
00:14:27.050
guess I should clarify the terminology
00:14:28.730
of it because I guess there's always a
00:14:30.020
point of confusion for beginners and as
00:14:31.760
it was for me basically a singleton
00:14:34.430
class is synonymous if I go in class and
00:14:36.080
a meta class is a kind of singleton
00:14:38.120
class but specifically it is a singleton
00:14:39.980
class of a class object so we speak of
00:14:42.860
the method class of dog but the
00:14:44.930
singleton class of Doge and since method
00:14:49.070
classes are also classes you can as meta
00:14:50.870
classes or method classes so methyl
00:14:52.520
methacrylate or meta meta classes in
00:14:55.100
general methods to the end classes
00:14:56.750
although you'll be like well pretty much
00:14:59.270
any N greater than one is practically
00:15:00.830
useless right but it's pretty fun to
00:15:03.020
know that ruby actually allows you to do
00:15:04.550
this and so is that let us talk about
00:15:07.520
method class creation
00:15:09.250
Boromir knows well that one does not
00:15:11.540
simply make a metal class and indeed if
00:15:14.959
you look at the make method last
00:15:17.390
function it is not easy to digest but
00:15:22.070
again it does basically three things
00:15:24.200
okay first we actually initialize our
00:15:26.839
new method class so we initialize a new
00:15:28.640
archive struct second we set the class
00:15:31.820
pointer of our class for the class point
00:15:33.740
off dog we set the class point of that
00:15:35.390
to point to our new meta class but we
00:15:37.940
also have to set the
00:15:39.110
Poynter of our new metaclass 2.2
00:15:42.010
something
00:15:43.160
and finally we set the super pointer of
00:15:46.910
our new metaclass 2.2 again something so
00:15:53.350
before we actually start setting them
00:15:55.700
class pointer of our new metal class
00:15:57.440
right our diagram looks like this again
00:16:00.440
it looks pretty simple we've just
00:16:02.240
created a new meta class of dog but you
00:16:04.730
notice that the class pointer it has to
00:16:06.529
go somewhere right so how do we set the
00:16:10.190
class pointer if you look at the logic
00:16:13.250
of the function you notice that we end
00:16:17.810
up calling this funny and true eigen
00:16:19.730
class macro and at the end of the day
00:16:22.190
what is Marko does is return the
00:16:24.470
metaclass
00:16:25.040
of class so in other words the
00:16:28.130
superclass of docs metaclass is classes
00:16:30.350
meta class and if transpose metaclass
00:16:32.329
hasn't already been created we have to
00:16:34.130
make it right so let's go and make the
00:16:35.750
meta classes class then same thing we
00:16:39.410
initialize our meta class of class and
00:16:41.300
now we meet the same problem we have to
00:16:43.550
set the class pointer of the metaclass
00:16:44.990
of class but how do we resolve it in
00:16:47.000
this case well it turns out that for the
00:16:48.890
metaclass of class its class pointer
00:16:50.420
just points back to itself and so our
00:16:53.240
diagram looks something like this so
00:16:55.940
we're happy of the class pointer but now
00:16:58.130
you notice you have another problem what
00:16:59.420
about the super well if you look at how
00:17:04.610
the super is set you realize again we
00:17:06.650
are calling this nth row eigen class
00:17:08.209
macro and the logic of this line is that
00:17:11.209
the superclass of dogs method class is
00:17:13.760
the method class of dogs
00:17:15.169
superclass or in other words the
00:17:19.069
metaclass of module so you see they were
00:17:22.579
setting off this whole chain reaction we
00:17:23.959
have to make the metaclass of module and
00:17:25.750
now we have to set the super off the
00:17:27.799
middle console module so by the same
00:17:29.240
logic the super of the metaclass of
00:17:30.500
module should be the meta class or
00:17:31.880
object and the super of the meta class
00:17:33.830
of object should be the method class of
00:17:35.720
basic object and now we have reached the
00:17:38.210
end of the chain so what should the
00:17:39.890
super off basically the method class of
00:17:41.510
basic object be so it turns out that
00:17:44.630
it's just class
00:17:47.950
and you notice that we actually haven't
00:17:51.460
finished creating our dot matter class
00:17:53.170
we still have to set it super pointer so
00:17:55.540
finally after creating all those meta
00:17:57.280
classes we can come back and set the
00:17:58.960
super pointer of our dot metaclass and
00:18:00.430
logics are same right the superclass of
00:18:02.830
dots meta class is a meta class of dog
00:18:04.480
superclass and so it's the meta class of
00:18:08.020
object so congratulations we are done
00:18:11.230
right all you wanted to do is create a
00:18:12.970
single dot class that we end up spawning
00:18:14.740
like five different classes and a
00:18:16.240
gazillion arrows along the way so indeed
00:18:18.850
Boromir was right and maybe at this
00:18:21.520
point all is my thought about stuff
00:18:23.200
insane but fret not because compared to
00:18:26.650
their making normal singleton classes is
00:18:28.270
the proverbial walk in the park and it
00:18:30.670
is evidenced by how short this function
00:18:32.170
is so again it does basically three
00:18:35.080
things but we actually initialize the
00:18:37.540
our class structure the new singleton
00:18:38.890
class and importantly we set the super
00:18:41.170
of this new Simonton class to point to
00:18:43.630
the original class of our instance
00:18:45.340
object so the original class although it
00:18:47.320
was dogs so we set the super of dojo
00:18:50.020
singleton class to point to dull and
00:18:53.430
then we actually set the class pointer
00:18:55.960
of those to point to this new singleton
00:18:58.120
class and finally we set the class
00:19:00.910
pointer of our new singleton class to
00:19:03.490
point to the metaclass of class and so
00:19:08.110
at the end of all this you have
00:19:09.190
something like that it's pretty much
00:19:10.780
real creation is left ops so at this
00:19:15.670
point you will realize that we are still
00:19:18.100
missing a pretty big part of Ruby's
00:19:19.960
object model which is modules so how
00:19:23.980
does including modules actually work and
00:19:25.720
the answer is that Ruby finds a pretty
00:19:28.090
clever way of sneaking modules into an
00:19:30.220
inheritance chain with something called
00:19:32.080
include classes so let's take a look how
00:19:35.470
that works I want to give I want to give
00:19:37.840
God some saber keys okay so I include
00:19:40.420
the saber teeth module in the doll class
00:19:43.230
what happens when I do this is that Ruby
00:19:46.390
creates a special kind of class for an
00:19:48.340
include class and inserts it to
00:19:50.620
inheritance chain just like so and a
00:19:53.230
special thing about this includes us is
00:19:55.030
that it actually shares the same method
00:19:56.740
table as our module and in this way
00:19:59.350
method dispatch just works like normal
00:20:01.180
right we just go up the inheritance
00:20:02.530
chain so this is where the bulk of the
00:20:06.430
module inclusion logic can be found this
00:20:08.710
include motivate function which honestly
00:20:10.900
speaking is really happy function I'm
00:20:13.360
not even sure if I compute understanding
00:20:14.770
at this point yet but this is the pre
00:20:16.690
part where we're actually creating our
00:20:18.370
new some include class and inserting it
00:20:21.280
into the inheritance chain with this our
00:20:23.290
class set super macro and I should
00:20:27.370
mention that since include classes and
00:20:29.620
modules we adjust our class trucks right
00:20:31.690
internally and Akash Choksi have a class
00:20:34.030
pointer so what what should a class
00:20:35.920
pointer be set to well for modules we
00:20:38.260
know the class pointer is set to modules
00:20:40.360
the capital M so the class of the
00:20:42.370
sabre-tooth module is module well it
00:20:44.950
turns out that the class of the
00:20:46.120
sabre-tooth include class as you can see
00:20:47.860
here is actually the module itself and
00:20:50.050
so the class pointer is how our include
00:20:52.270
class keeps track of the module was
00:20:54.190
created from so if you include multiple
00:20:58.840
modules in a class so instead of just
00:21:02.080
you know saber teeth I want to give Doge
00:21:03.730
some sunglasses cause it's cool right so
00:21:05.650
if I do that because the include model
00:21:08.830
set function is called everytime include
00:21:11.500
Sigma's evaluated by the logic of how
00:21:13.390
the include classes inserted into the
00:21:15.160
inheritance chain the module that
00:21:17.500
included later is basically has its
00:21:18.910
include class inserted lower down the
00:21:20.590
chain or in other words we look up its
00:21:22.180
method table first so that has now
00:21:26.350
complicate things a bit let us talk
00:21:28.990
about including modules in modules now
00:21:35.110
at this point I should emphasize again
00:21:36.520
that modules include classes out just
00:21:38.320
our class traps and other in the class
00:21:39.820
pointer our class rocks will have a
00:21:41.410
super pointer right and maybe at this
00:21:44.290
point you're like but can modules have a
00:21:46.360
super and the answer is yes but not by
00:21:50.890
default
00:21:51.400
by default the super is just now but the
00:21:54.010
super comes in handy when we want to
00:21:55.480
include modules in modules so let's take
00:21:58.090
a look at how that works
00:21:59.490
instead of giving Doge saber teeth and
00:22:01.900
sunglasses I want to give him a pair of
00:22:03.520
super cheap sunglasses
00:22:04.840
how cool is that right so first I
00:22:07.480
include the saber teeth module in the
00:22:09.250
sunglasses module and then I finally
00:22:11.200
include the sunglasses module in my dog
00:22:13.270
class
00:22:14.580
what happens when I include a module no
00:22:16.780
module is really not too different from
00:22:18.310
what happens when I include a module in
00:22:20.020
a class basically I create an include
00:22:22.840
class of the included module and I set
00:22:25.390
the super pointer of the module I'm
00:22:27.400
including that module in to point to the
00:22:29.890
include class right so now the super
00:22:31.960
pointer of the sunglasses module points
00:22:33.700
to the saber teeth include class and
00:22:35.670
finally when I actually include the
00:22:37.840
sunglasses module in dog I just get to
00:22:40.090
include classes inserted into the
00:22:41.710
inheritance chain just like this all
00:22:46.810
right so awesome ice cover love drown
00:22:48.730
I've talked about how classes and
00:22:50.890
objects actually represented in Ruby how
00:22:53.380
singleton classes and meta classes
00:22:54.700
actually created and how mod is actually
00:22:57.430
work like how including what is actually
00:22:59.140
working and extending modules isn't much
00:23:00.520
fun in either so before I wrap up I
00:23:03.670
would be remiss not to mention just to
00:23:06.040
clarify the distinction between the C
00:23:07.990
class and super pointers and the Ruby
00:23:09.760
class and super class methods so why do
00:23:11.260
they seem to give different results when
00:23:13.900
the answer is all pretty simply that
00:23:15.550
Ruby's class method it does follow the
00:23:19.090
class pointer in the C struct but it
00:23:20.740
just ignores singleton classes and
00:23:22.360
include classes along the way and so the
00:23:25.540
class of the docs and the dot singleton
00:23:28.150
class is still class right and Ruby's
00:23:32.710
superclass method it also follows the
00:23:34.960
super pointer of the C struct but it
00:23:37.060
just ignores
00:23:37.690
insuit classes along the way and so even
00:23:40.210
though the super of our dog class here
00:23:41.680
is actually the Sabre T's include class
00:23:43.720
its superclass is still object so maybe
00:23:50.080
at this point you're like yeah this
00:23:52.060
another hood internal stuff it is fun to
00:23:54.490
know about why I mean it's not going to
00:23:58.150
make me a better Ruby programmer in my
00:23:59.770
day to day or anything right and yeah I
00:24:02.560
guess you know to a certain extent I
00:24:04.300
agree I know it's not practically
00:24:06.220
helpful to know that I can create metal
00:24:08.020
metal metal metal metal metal metal
00:24:10.450
metal classes but I like to think that
00:24:13.890
I'm just having a solid understanding of
00:24:16.600
Ruby's object model does help you reason
00:24:18.010
about your code better more clearly and
00:24:20.290
if in the future you ever meet you know
00:24:22.690
potentially confusing situations such as
00:24:24.640
all of this I mean there's no need for
00:24:27.100
me to even talk about
00:24:28.040
the not just because I'm running out of
00:24:30.860
time but me mostly because you now have
00:24:35.000
the mental model to figure out all by
00:24:36.950
yourself the mental model that I wish I
00:24:39.560
had starting out and more so thank you
00:24:54.559
okay any questions one life no one has
00:25:06.899
questions oh okay yeah oh oh hi first
00:25:17.100
off that was amazing that was an amazing
00:25:19.139
presentation thank you my question is
00:25:21.869
how did you learn all this stuff or did
00:25:24.299
you just read through the C file or oh
00:25:26.730
yeah so I think my own last year I've I
00:25:29.730
saw this book movie under the microscope
00:25:31.409
and actually I I kind of looked through
00:25:34.769
the saucy failures as I was running why
00:25:36.809
am i reading this and put aside and
00:25:39.330
after a while I decided to hey maybe I
00:25:41.730
should you know it's fun to know this
00:25:43.409
internal stuff so I decided to poke
00:25:44.850
around the few resource but of course as
00:25:46.559
a beginner I was like how do I
00:25:47.879
understand all of this and then I found
00:25:49.409
this really good resource called the
00:25:50.730
Ruby hacking guide by I think by written
00:25:54.720
by algy Minoru it is actually for ruby
00:25:57.450
1.8 but I mean the internals the base of
00:26:00.419
the call for me hasn't really changed
00:26:01.379
all that much means that the VM they've
00:26:03.419
written a new VM right and all that so
00:26:05.369
it was still really helpful for me and
00:26:07.470
understanding how you know the C Ruby
00:26:09.359
code is laid out so if you're interested
00:26:10.710
in checking it out definitely look at
00:26:12.119
look of the Ruby hacking guide yeah
00:26:14.489
thank you
00:26:21.380
so Aaron kind of still half of my
00:26:23.789
question but so when you started out
00:26:26.850
researching this did you expect to get
00:26:29.159
that far down the rabbit hole or like
00:26:31.139
that you actually sit out to find out
00:26:33.059
all of that all the way or did it just
00:26:36.360
happen and you started opinion is like
00:26:38.130
damn like where does that leave Inslee
00:26:39.990
well and I always so the initial
00:26:43.260
ambition was let me just try to give a
00:26:45.389
talk rtrc hmm what topic can I talk
00:26:47.850
about and as a beginner I'm not a
00:26:50.159
professional so I don't I can't on my
00:26:51.539
project I don't really have project to
00:26:52.950
talk about everything so okay I mean let
00:26:54.990
me dig into some goofy stuff and so yeah
00:26:57.659
it kind of just like yeah let me try
00:26:59.700
that because the object Ruby's object
00:27:01.380
model is pretty fun right when I realize
00:27:04.049
that does this whole infinite you know
00:27:06.299
infinite metaclass thing going on as I
00:27:08.340
yeah let me poke wanted it and then yeah
00:27:11.610
like that you say I just poked into it
00:27:13.980
poked around and just end up well like
00:27:16.289
this is all the stuff that goes on and
00:27:17.970
just like that escalated quickly
00:27:19.559
yeah cool thank you thank you
00:27:26.680
hey once you learned all this stuff
00:27:29.150
did it change the way that you now write
00:27:31.370
Ruby code like understanding it does it
00:27:34.040
di Denton starts using modules more
00:27:36.080
often did you start extending included
00:27:38.720
modules etc I mean definitely I guess I
00:27:41.240
will understand a lot of metal
00:27:42.560
programming stuff better now because I
00:27:44.270
mean all this life a lot of people use
00:27:46.520
like I don't know like class class
00:27:49.790
method or class method module and indeed
00:27:51.320
have a self going to the hook and I what
00:27:53.030
all this do so definitely that helps me
00:27:55.400
understand this more confusing metal
00:27:57.140
programming stuff
00:27:57.950
no but you mean confession is that I
00:28:00.950
haven't actually done Ruby for quite a
00:28:02.000
bit because I don't actually use it for
00:28:04.220
what school yeah so how did you find out
00:28:12.500
about the meta meta meta stuff did you
00:28:15.500
read that in some book or in the C code
00:28:18.410
or did you use like clips and overrode
00:28:21.410
like inherited or something about what
00:28:23.270
actually is in Ruby Docs itself so if
00:28:25.310
you look at the class documentation
00:28:26.960
there's a you know a memorization the
00:28:29.300
class the class hierarchy and then
00:28:31.490
there's a chain of dashes off into
00:28:33.470
infinity so that when I knew something
00:28:35.750
sneaky ago I saw that so like years ago
00:28:37.670
I never understood why they're like what
00:28:39.740
what does it mean like just dot dot dot
00:28:41.480
no no you know okay thank you
00:28:47.290
any other questions
00:28:56.919
no okay thank you very much in tiegler's
00:28:59.599
having our own love