SlideShare a Scribd company logo
1 of 104
metawhat?
   a look into the mysterious
metaclass and Ruby’s object model




                       Brandon Dimcheff
                                  @bdimcheff
                            Ruby Midwest 2010
class << self
class Foo
 class << self
   def bar
    "hello"
   end
 end
end

Foo.bar # => "hello"
class Foo
 class << self
   def bar
    "hello"
   end
 end
end

Foo.bar # => "hello"
what’s an object?
struct RObject {
   struct RBasic basic;
   struct st_table *iv_tbl;
};




                  ruby.h
struct RObject {
   struct RBasic basic;
   struct st_table *iv_tbl;
};

struct RBasic {
   unsigned long flags;
   VALUE klass;
};

                  ruby.h
struct RObject {
   struct RBasic basic;
   struct st_table *iv_tbl;
};

struct RBasic {
   unsigned long flags;
   VALUE klass;
};

                  ruby.h
what is an object?

     foo        class
   ivar hash
objects don’t have
    methods
struct RClass {
   struct RBasic basic;
   struct st_table *iv_tbl;
   struct st_table *m_tbl;
   VALUE super;
};



                 ruby.h
RObject
struct RClass {
   struct RBasic basic;
   struct st_table *iv_tbl;
   struct st_table *m_tbl;
   VALUE super;
};



                 ruby.h
struct RClass {
   struct RBasic basic;
   struct st_table *iv_tbl;
   struct st_table *m_tbl;
   VALUE super;               methods
};



                 ruby.h
struct RClass {
   struct RBasic basic;
   struct st_table *iv_tbl;
   struct st_table *m_tbl;
   VALUE super;                       methods
};
                      superclass pointer


                 ruby.h
what is a class?



          super
       Bar
                  class
     ivar hash

     methods
super
                      Bar
                                 class
                    ivar hash
  foo       class
ivar hash           methods
super
                                  Object

                      Bar
                                 class
                    ivar hash
  foo       class
ivar hash           methods
method dispatch
method dispatch

1. Follow my class pointer
method dispatch

1. Follow my class pointer
2. Check the methods table for my method
method dispatch

1. Follow my class pointer
2. Check the methods table for my method
3. Call the method, or follow the super
   pointer if the method doesn’t exist
method dispatch

1. Follow my class pointer
2. Check the methods table for my method
3. Call the method, or follow the super
   pointer if the method doesn’t exist
4. Repeat 2-3 if the method was not found
method dispatch




                         super
                      Bar
                                 class
                    ivar hash
  foo       class
ivar hash           methods
method dispatch




                                   super
1. Follow the class pointer     Bar
                                           class
                              ivar hash
        foo           class
     ivar hash                methods
method dispatch




                                   super
1. Follow the class pointer     Bar
                                           class
                              ivar hash
        foo           class
     ivar hash                methods

  2. Check the method table
method dispatch




                                       super
    3. Follow the super pointer


1. Follow the class pointer         Bar
                                               class
                                  ivar hash
        foo           class
     ivar hash                    methods

  2. Check the method table
class Primate
 def opposable_thumbs
   true
 end
end

bob = Primate.new
bob.opposable_thumbs # => true
Bob
Object




                   super
      class
bob           Primate
Object

bob.opposable_thumbs




                                super
                   class
          bob              Primate
Object

bob.opposable_thumbs




                                super
                   class
          bob              Primate
Object

bob.opposable_thumbs




                                super
                   class
          bob              Primate




                               me
                                   tho
                                        ds
Object

bob.opposable_thumbs




                                super
                   class
          bob              Primate




                               me
                                   tho
                                        ds
                            #opposable_thumbs
Object

bob.opposable_thumbs




                                super
                   class
          bob              Primate




                               me
                                   tho
                                        ds
                            #opposable_thumbs
                                # => true
joe = Primate.new

def joe.opposable_thumbs
 false
end

joe.opposable_thumbs # => false
bob.opposable_thumbs # => true
Joe
Pretend this is
         missing




Joe
Object




                   super
      class
joe           Primate
Object

joe.opposable_thumbs




                                    super
                       class
          joe                  Primate
Object

joe.opposable_thumbs




                                    super
                       class
          joe                  Primate
Object

joe.opposable_thumbs




                                    super
                       class
          joe                  Primate




                                    me
                                        tho
                                            ds
Object

joe.opposable_thumbs




                                    super
                       class
          joe                  Primate




                                    me
                                        tho
                                            ds
                                #opposable_thumbs
Object

joe.opposable_thumbs




                                    super
                       class
          joe                  Primate




                                    me
                                        tho
                                            ds
                                #opposable_thumbs
                                  # => true :( :( :(
Object




                   super
              Primate




                   super
      class
joe            joe'
Object




                                    super
                               Primate


joe.opposable_thumbs




                                    super
                       class
           joe                  joe'
Object




                                    super
                               Primate


joe.opposable_thumbs




                                    super
                       class
           joe                  joe'
Object




                                    super
                               Primate


joe.opposable_thumbs




                                    super
                       class                meth
           joe                  joe'            ods
Object




                                    super
                               Primate


joe.opposable_thumbs




                                    super
                       class                meth
           joe                  joe'            ods
                                             #opposable_thumbs
Object




                                    super
                               Primate


joe.opposable_thumbs




                                    super
                       class                meth
           joe                  joe'            ods
                                             #opposable_thumbs
                                                 # => false :)
Object




                                    super
                                            meth
                               Primate          ods

joe.opposable_thumbs




                                    super
                       class                meth
           joe                  joe'            ods
                                             #opposable_thumbs
                                                 # => false :)
Object




                                    super
                                            meth
                               Primate          ods
                                             #opposable_thumbs
joe.opposable_thumbs




                                    super
                       class                meth
           joe                  joe'            ods
                                             #opposable_thumbs
                                                 # => false :)
Object




                                    super
                                            meth
                               Primate          ods
                                             #opposable_thumbs
joe.opposable_thumbs                              # => true



                                    super
                       class                meth
           joe                  joe'            ods
                                             #opposable_thumbs
                                                 # => false :)
Object




                                    super
                       class                meth
           bob                 Primate          ods
                                             #opposable_thumbs
joe.opposable_thumbs                              # => true



                                    super
                       class                meth
           joe                  joe'            ods
                                             #opposable_thumbs
                                                 # => false :)
Object




                   super
              Primate




                   super
                           Joe’s Singleton Class
      class
joe            joe'
Metaclass
                Singleton Class


   Eigenclass


            Virtual Class
Metaclass
                Singleton Class


   Eigenclass


            Virtual Class
bob.class # => Primate
bob.class # => Primate
joe.class # => Primate
class Primate
 class << self
   def species
    ["lemur", "monkey", "human"]
   end
 end
end

Primate.species # => ["lemur", ...]
joe = Primate.new

def joe.opposable_thumbs
 false
end

joe.opposable_thumbs # => false
Primate = Class.new

def Primate.species
 ["lemur", "monkey", "human"]
end

Primate.species # => ["lemur",
"monkey", "human"]
Object




                      super
          class
Primate           Class
Object

Primate.species




                         super
             class
Primate              Class
Object

Primate.species




                         super
             class
Primate              Class
Object

Primate.species




                         super
             class
Primate              Class




                       me
                         tho
                              ds
Object

Primate.species




                         super
             class
Primate              Class




                       me
                         tho
                              ds
                        #species
                      NoMethodError
Object




                       super
                   Class




                       super
          class
Primate           Primate'
Object




                        super
                    Class

 Primate.species



                        super
           class
Primate            Primate'
Object




                        super
                    Class

 Primate.species



                        super
           class
Primate            Primate'
Object




                        super
                    Class

 Primate.species



                        super
           class                meth
Primate            Primate'         ods
Object




                        super
                    Class

 Primate.species



                        super
           class                meth
Primate            Primate'         ods
                                      #species
Object




                        super
                    Class

 Primate.species



                        super
           class                meth
Primate            Primate'         ods
                                      #species
                                   # => [“lemur”, ...]
Object




                        super
                                meth
                                    ods
                    Class

 Primate.species



                        super
           class                meth
Primate            Primate'         ods
                                       #species
                                    # => [“lemur”, ...]
Object




                        super
                                meth
                                    ods
                    Class
                                       #species
 Primate.species



                        super
           class                meth
Primate            Primate'         ods
                                       #species
                                    # => [“lemur”, ...]
Object




                       super
                   Class




                       super
                               Primate’s Singleton
                                Class (Metaclass)
          class
Primate           Primate'
a metaclass is a
singleton class of a class
        (to some people, anyways)
super



Object               Class
    super




                         super
            class
Primate             Primate'
all classes have
singletons/metaclasses
     automatically
super


                        Class




                            super
            class
Object                 Object'
    super




                            super
            class
Primate                Primate'
super


                                     Class




                                         super
def Object.foo

                         class
            Object                  Object'
                 super




                                         super
                         class
            Primate                 Primate'
super


                                      Class




                                          super
def Object.foo

                          class
              Object                 Object'
                  super




                                          super
Primate.foo

                          class
              Primate                Primate'
super


                                      Class




                                          super
def Object.foo

                          class
              Object                 Object'
                  super




                                          super
Primate.foo
                                                  meth
                          class                       ods
              Primate                Primate'
                                                        #species
super


                                      Class




                                          super
def Object.foo
                                                  meth
                                                      ods
                          class
              Object                 Object'                #foo
                  super




                                          super
Primate.foo
                                                  meth
                          class                       ods
              Primate                Primate'
                                                        #species
super



                      Module




                           super
                       Class




                           super
              class
Object                Object'
    super




              class        super
Primate               Primate'
super



                                     Module




                                          super
                                      Class




                                          super
                            class
              Object                 Object'




                  super




                                          super
                            class
              Primate                Primate'
                  super




      class                  class
joe            joe'
super



                                   Module




                                   super
              Kernel                Class




              super




                                   super
                          class
              Object               Object'



              super




                                   super
                          class
              Primate              Primate'
              super




      class                class
joe              joe'
super



                     BasicObject              Module


1 .9




                                              super
                       super
                       Kernel                   Class




                       super




                                              super
                                     class
                       Object                 Object'



                       super




                                              super
                                     class
                      Primate                 Primate'
                       super




             class                    class
       joe                joe'
give me your
singleton class!
class Object
   # The hidden singleton lurks behind everyone
   def metaclass
    class << self
     self
    end
   end

   def meta_eval(&blk)
    metaclass.instance_eval(&blk)
   end

   # Adds methods to a metaclass
   def meta_def(name, &blk)
     meta_eval { define_method(name, &blk) }
   end

  # Defines an instance method within a class
  def class_def(name, &blk)
    class_eval { define_method(name, &blk) }
  end
end                http://code.whytheluckystiff.net/metaid/
class Object
   # The hidden singleton lurks behind everyone
   def metaclass
    class << self
     self
    end
   end

   def meta_eval(&blk)
    metaclass.instance_eval(&blk)
   end

   # Adds methods to a metaclass
   def meta_def(name, &blk)
     meta_eval { define_method(name, &blk) }
   end

  # Defines an instance method within a class
  def class_def(name, &blk)
    class_eval { define_method(name, &blk) }
  end
end                http://code.whytheluckystiff.net/metaid/
class Object
   # The hidden singleton lurks behind everyone
   def metaclass
    class << self
     self
    end
   end

   def meta_eval(&blk)
    metaclass.instance_eval(&blk)
   end

   # Adds methods to a metaclass
   def meta_def(name, &blk)
     meta_eval { define_method(name, &blk) }
   end

  # Defines an instance method within a class
  def class_def(name, &blk)
    class_eval { define_method(name, &blk) }
  end
end                http://code.whytheluckystiff.net/metaid/
ruby 1.9

# Object.singleton_class
joe.singleton_class

# Object#define_singleton_method
joe.define_singleton_method(:opposable_thumbs) do
  false
end
def method
     defines an instance method on Primate


class Primate
 # def defines a method on self
 def opposable_thumbs
   true
 end
end
def object.method
    defines a method on the singleton of Primate


class Primate
 # defines a method on the singleton of self
 # self is the class Primate
 def self.species
   ["Lemur", "Monkey", "Human"]
 end
end
class << o; def
defines a method on the singleton of Primate


class << Primate
 # in the singleton class of Primate
 def species
   ["Lemur", "Monkey", "Human"]
 end
end
class <<
class << my_object
 # in the context of the
 # singleton class of my_object
end
class <<
class << my_object
 # in the context of the
 # singleton class of my_object
end

class Primate
 # in the context
 # of class Primate
end
class Foo
 class << self
   def bar
    "hello"
   end
 end
end

Foo.bar # => "hello"
include vs. extend
module ThumbsUp
 def opposable_thumbs; true; end
end

module Species
 def species; ["Lemur", "Monkey", "Human"]; end
end

class Primate
 # adds methods to the class Primate
 include ThumbsUp

 # adds methods to the singleton of Primate
 extend Species
end
instance.extend

module ThumbsDown
 def opposable_thumbs; false; end
end

joe = Primate.new
joe.extend(ThumbsDown)
object.extend(Foo)

object.singleton_class.include(Foo)
?
Brandon Dimcheff
              http://spkr8.com/t/3756
             brandon@dimcheff.com
                  twitter: @bdimcheff
         http://brandon.dimcheff.com
      #midwest.rb on irc.freenode.net
Bob - http://en.wikipedia.org/wiki/File:Tamarin_portrait_2_edit3.jpg
Joe - http://upload.wikimedia.org/wikipedia/commons/e/ec/Tarsier_Hugs_Mossy_Branch.jpg

More Related Content

Recently uploaded

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 

Recently uploaded (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

metawhat?

  • 1. metawhat? a look into the mysterious metaclass and Ruby’s object model Brandon Dimcheff @bdimcheff Ruby Midwest 2010
  • 3. class Foo class << self def bar "hello" end end end Foo.bar # => "hello"
  • 4. class Foo class << self def bar "hello" end end end Foo.bar # => "hello"
  • 6. struct RObject { struct RBasic basic; struct st_table *iv_tbl; }; ruby.h
  • 7. struct RObject { struct RBasic basic; struct st_table *iv_tbl; }; struct RBasic { unsigned long flags; VALUE klass; }; ruby.h
  • 8. struct RObject { struct RBasic basic; struct st_table *iv_tbl; }; struct RBasic { unsigned long flags; VALUE klass; }; ruby.h
  • 9. what is an object? foo class ivar hash
  • 11. struct RClass { struct RBasic basic; struct st_table *iv_tbl; struct st_table *m_tbl; VALUE super; }; ruby.h
  • 12. RObject struct RClass { struct RBasic basic; struct st_table *iv_tbl; struct st_table *m_tbl; VALUE super; }; ruby.h
  • 13. struct RClass { struct RBasic basic; struct st_table *iv_tbl; struct st_table *m_tbl; VALUE super; methods }; ruby.h
  • 14. struct RClass { struct RBasic basic; struct st_table *iv_tbl; struct st_table *m_tbl; VALUE super; methods }; superclass pointer ruby.h
  • 15. what is a class? super Bar class ivar hash methods
  • 16. super Bar class ivar hash foo class ivar hash methods
  • 17. super Object Bar class ivar hash foo class ivar hash methods
  • 19. method dispatch 1. Follow my class pointer
  • 20. method dispatch 1. Follow my class pointer 2. Check the methods table for my method
  • 21. method dispatch 1. Follow my class pointer 2. Check the methods table for my method 3. Call the method, or follow the super pointer if the method doesn’t exist
  • 22. method dispatch 1. Follow my class pointer 2. Check the methods table for my method 3. Call the method, or follow the super pointer if the method doesn’t exist 4. Repeat 2-3 if the method was not found
  • 23. method dispatch super Bar class ivar hash foo class ivar hash methods
  • 24. method dispatch super 1. Follow the class pointer Bar class ivar hash foo class ivar hash methods
  • 25. method dispatch super 1. Follow the class pointer Bar class ivar hash foo class ivar hash methods 2. Check the method table
  • 26. method dispatch super 3. Follow the super pointer 1. Follow the class pointer Bar class ivar hash foo class ivar hash methods 2. Check the method table
  • 27. class Primate def opposable_thumbs true end end bob = Primate.new bob.opposable_thumbs # => true
  • 28. Bob
  • 29. Object super class bob Primate
  • 30. Object bob.opposable_thumbs super class bob Primate
  • 31. Object bob.opposable_thumbs super class bob Primate
  • 32. Object bob.opposable_thumbs super class bob Primate me tho ds
  • 33. Object bob.opposable_thumbs super class bob Primate me tho ds #opposable_thumbs
  • 34. Object bob.opposable_thumbs super class bob Primate me tho ds #opposable_thumbs # => true
  • 35. joe = Primate.new def joe.opposable_thumbs false end joe.opposable_thumbs # => false bob.opposable_thumbs # => true
  • 36. Joe
  • 37. Pretend this is missing Joe
  • 38. Object super class joe Primate
  • 39. Object joe.opposable_thumbs super class joe Primate
  • 40. Object joe.opposable_thumbs super class joe Primate
  • 41. Object joe.opposable_thumbs super class joe Primate me tho ds
  • 42. Object joe.opposable_thumbs super class joe Primate me tho ds #opposable_thumbs
  • 43. Object joe.opposable_thumbs super class joe Primate me tho ds #opposable_thumbs # => true :( :( :(
  • 44. Object super Primate super class joe joe'
  • 45. Object super Primate joe.opposable_thumbs super class joe joe'
  • 46. Object super Primate joe.opposable_thumbs super class joe joe'
  • 47. Object super Primate joe.opposable_thumbs super class meth joe joe' ods
  • 48. Object super Primate joe.opposable_thumbs super class meth joe joe' ods #opposable_thumbs
  • 49. Object super Primate joe.opposable_thumbs super class meth joe joe' ods #opposable_thumbs # => false :)
  • 50. Object super meth Primate ods joe.opposable_thumbs super class meth joe joe' ods #opposable_thumbs # => false :)
  • 51. Object super meth Primate ods #opposable_thumbs joe.opposable_thumbs super class meth joe joe' ods #opposable_thumbs # => false :)
  • 52. Object super meth Primate ods #opposable_thumbs joe.opposable_thumbs # => true super class meth joe joe' ods #opposable_thumbs # => false :)
  • 53. Object super class meth bob Primate ods #opposable_thumbs joe.opposable_thumbs # => true super class meth joe joe' ods #opposable_thumbs # => false :)
  • 54. Object super Primate super Joe’s Singleton Class class joe joe'
  • 55. Metaclass Singleton Class Eigenclass Virtual Class
  • 56. Metaclass Singleton Class Eigenclass Virtual Class
  • 57. bob.class # => Primate
  • 58. bob.class # => Primate joe.class # => Primate
  • 59. class Primate class << self def species ["lemur", "monkey", "human"] end end end Primate.species # => ["lemur", ...]
  • 60. joe = Primate.new def joe.opposable_thumbs false end joe.opposable_thumbs # => false
  • 61. Primate = Class.new def Primate.species ["lemur", "monkey", "human"] end Primate.species # => ["lemur", "monkey", "human"]
  • 62. Object super class Primate Class
  • 63. Object Primate.species super class Primate Class
  • 64. Object Primate.species super class Primate Class
  • 65. Object Primate.species super class Primate Class me tho ds
  • 66. Object Primate.species super class Primate Class me tho ds #species NoMethodError
  • 67. Object super Class super class Primate Primate'
  • 68. Object super Class Primate.species super class Primate Primate'
  • 69. Object super Class Primate.species super class Primate Primate'
  • 70. Object super Class Primate.species super class meth Primate Primate' ods
  • 71. Object super Class Primate.species super class meth Primate Primate' ods #species
  • 72. Object super Class Primate.species super class meth Primate Primate' ods #species # => [“lemur”, ...]
  • 73. Object super meth ods Class Primate.species super class meth Primate Primate' ods #species # => [“lemur”, ...]
  • 74. Object super meth ods Class #species Primate.species super class meth Primate Primate' ods #species # => [“lemur”, ...]
  • 75. Object super Class super Primate’s Singleton Class (Metaclass) class Primate Primate'
  • 76. a metaclass is a singleton class of a class (to some people, anyways)
  • 77. super Object Class super super class Primate Primate'
  • 79. super Class super class Object Object' super super class Primate Primate'
  • 80. super Class super def Object.foo class Object Object' super super class Primate Primate'
  • 81. super Class super def Object.foo class Object Object' super super Primate.foo class Primate Primate'
  • 82. super Class super def Object.foo class Object Object' super super Primate.foo meth class ods Primate Primate' #species
  • 83. super Class super def Object.foo meth ods class Object Object' #foo super super Primate.foo meth class ods Primate Primate' #species
  • 84. super Module super Class super class Object Object' super class super Primate Primate'
  • 85. super Module super Class super class Object Object' super super class Primate Primate' super class class joe joe'
  • 86. super Module super Kernel Class super super class Object Object' super super class Primate Primate' super class class joe joe'
  • 87. super BasicObject Module 1 .9 super super Kernel Class super super class Object Object' super super class Primate Primate' super class class joe joe'
  • 89. class Object # The hidden singleton lurks behind everyone def metaclass class << self self end end def meta_eval(&blk) metaclass.instance_eval(&blk) end # Adds methods to a metaclass def meta_def(name, &blk) meta_eval { define_method(name, &blk) } end # Defines an instance method within a class def class_def(name, &blk) class_eval { define_method(name, &blk) } end end http://code.whytheluckystiff.net/metaid/
  • 90. class Object # The hidden singleton lurks behind everyone def metaclass class << self self end end def meta_eval(&blk) metaclass.instance_eval(&blk) end # Adds methods to a metaclass def meta_def(name, &blk) meta_eval { define_method(name, &blk) } end # Defines an instance method within a class def class_def(name, &blk) class_eval { define_method(name, &blk) } end end http://code.whytheluckystiff.net/metaid/
  • 91. class Object # The hidden singleton lurks behind everyone def metaclass class << self self end end def meta_eval(&blk) metaclass.instance_eval(&blk) end # Adds methods to a metaclass def meta_def(name, &blk) meta_eval { define_method(name, &blk) } end # Defines an instance method within a class def class_def(name, &blk) class_eval { define_method(name, &blk) } end end http://code.whytheluckystiff.net/metaid/
  • 92. ruby 1.9 # Object.singleton_class joe.singleton_class # Object#define_singleton_method joe.define_singleton_method(:opposable_thumbs) do false end
  • 93. def method defines an instance method on Primate class Primate # def defines a method on self def opposable_thumbs true end end
  • 94. def object.method defines a method on the singleton of Primate class Primate # defines a method on the singleton of self # self is the class Primate def self.species ["Lemur", "Monkey", "Human"] end end
  • 95. class << o; def defines a method on the singleton of Primate class << Primate # in the singleton class of Primate def species ["Lemur", "Monkey", "Human"] end end
  • 96. class << class << my_object # in the context of the # singleton class of my_object end
  • 97. class << class << my_object # in the context of the # singleton class of my_object end class Primate # in the context # of class Primate end
  • 98. class Foo class << self def bar "hello" end end end Foo.bar # => "hello"
  • 99. include vs. extend module ThumbsUp def opposable_thumbs; true; end end module Species def species; ["Lemur", "Monkey", "Human"]; end end class Primate # adds methods to the class Primate include ThumbsUp # adds methods to the singleton of Primate extend Species end
  • 100. instance.extend module ThumbsDown def opposable_thumbs; false; end end joe = Primate.new joe.extend(ThumbsDown)
  • 102. ?
  • 103. Brandon Dimcheff http://spkr8.com/t/3756 brandon@dimcheff.com twitter: @bdimcheff http://brandon.dimcheff.com #midwest.rb on irc.freenode.net
  • 104. Bob - http://en.wikipedia.org/wiki/File:Tamarin_portrait_2_edit3.jpg Joe - http://upload.wikimedia.org/wikipedia/commons/e/ec/Tarsier_Hugs_Mossy_Branch.jpg

Editor's Notes

  1. you care because you want to know how your tools actually work
  2. how many have seen this? how many have written this? not for class methods? cout?
  3. this is what I first used class &lt;&lt; self for we want class methods
  4. objects just instance variables + pointer to a class no methods
  5. objects just instance variables + pointer to a class no methods
  6. notice there is no methods/behavior by process of elimination, methods are stored on the class
  7. class is an object with behavior and a superclass
  8. class is an object with behavior and a superclass
  9. class is an object with behavior and a superclass
  10. class is an object with behavior and a superclass
  11. class is an object with behavior and a superclass
  12. class is an object with behavior and a superclass
  13. how do we call methods on foo?
  14. how do we call methods on foo?
  15. Gradually build up object model by using method dispatch as a guide eventually call method_missing
  16. Gradually build up object model by using method dispatch as a guide eventually call method_missing
  17. Gradually build up object model by using method dispatch as a guide eventually call method_missing
  18. Gradually build up object model by using method dispatch as a guide eventually call method_missing
  19. bob&amp;#x2019;s class is primate, primate is a sublass of Object
  20. bob&amp;#x2019;s class is primate, primate is a sublass of Object
  21. bob&amp;#x2019;s class is primate, primate is a sublass of Object
  22. bob&amp;#x2019;s class is primate, primate is a sublass of Object
  23. bob&amp;#x2019;s class is primate, primate is a sublass of Object
  24. bob&amp;#x2019;s class is primate, primate is a sublass of Object
  25. bob&amp;#x2019;s class is primate, primate is a sublass of Object
  26. bob&amp;#x2019;s class is primate, primate is a sublass of Object
  27. instance-specific behavior
  28. singleton classes define instance-specific behavior
  29. singleton classes define instance-specific behavior
  30. singleton classes define instance-specific behavior
  31. singleton classes define instance-specific behavior
  32. singleton classes define instance-specific behavior
  33. singleton classes define instance-specific behavior
  34. singleton classes define instance-specific behavior
  35. singleton classes define instance-specific behavior
  36. singleton classes define instance-specific behavior
  37. singleton classes define instance-specific behavior
  38. singleton classes define instance-specific behavior
  39. singleton classes define instance-specific behavior
  40. singleton classes define instance-specific behavior
  41. singleton classes define instance-specific behavior
  42. singleton classes define instance-specific behavior
  43. singleton classes define instance-specific behavior
  44. singleton classes define instance-specific behavior
  45. singleton classes define instance-specific behavior
  46. singleton classes define instance-specific behavior
  47. singleton classes define instance-specific behavior
  48. singleton classes define instance-specific behavior
  49. singleton classes define instance-specific behavior
  50. singleton classes define instance-specific behavior
  51. singleton classes define instance-specific behavior
  52. singleton classes define instance-specific behavior
  53. singleton classes define instance-specific behavior
  54. many different names slight differences in meaning sometimes singleton class stores instance-specific behavior created automatically on request (class &lt;&lt; obj) classes are objects metaclasses store instance specific behavior for classes
  55. ruby magic to hide the singleton groovy has explicit access to singleton
  56. remember when we defined instance specific methods on joe
  57. instance-specific behavior is class methods dereference class pointer, look up method, climb inheritance chain class of Primate is class b/c we did Class.new
  58. instance-specific behavior is class methods dereference class pointer, look up method, climb inheritance chain class of Primate is class b/c we did Class.new
  59. instance-specific behavior is class methods dereference class pointer, look up method, climb inheritance chain class of Primate is class b/c we did Class.new
  60. instance-specific behavior is class methods dereference class pointer, look up method, climb inheritance chain class of Primate is class b/c we did Class.new
  61. instance-specific behavior is class methods dereference class pointer, look up method, climb inheritance chain class of Primate is class b/c we did Class.new
  62. instance-specific behavior is class methods dereference class pointer, look up method, climb inheritance chain class of Primate is class b/c we did Class.new
  63. instance-specific behavior is class methods dereference class pointer, look up method, climb inheritance chain class of Primate is class b/c we did Class.new
  64. instance-specific behavior is class methods dereference class pointer, look up method, climb inheritance chain class of Primate is class b/c we did Class.new
  65. Missing Primate&amp;#x2019;s superclass (Object)
  66. Missing Primate&amp;#x2019;s superclass (Object)
  67. Missing Primate&amp;#x2019;s superclass (Object)
  68. Missing Primate&amp;#x2019;s superclass (Object)
  69. Missing Primate&amp;#x2019;s superclass (Object)
  70. Missing Primate&amp;#x2019;s superclass (Object)
  71. Missing Primate&amp;#x2019;s superclass (Object)
  72. Missing Primate&amp;#x2019;s superclass (Object)
  73. Missing Primate&amp;#x2019;s superclass (Object)
  74. Missing Primate&amp;#x2019;s superclass (Object)
  75. Missing Primate&amp;#x2019;s superclass (Object)
  76. Missing Primate&amp;#x2019;s superclass (Object)
  77. Missing Primate&amp;#x2019;s superclass (Object)
  78. Missing Primate&amp;#x2019;s superclass (Object)
  79. Missing Primate&amp;#x2019;s superclass (Object)
  80. Missing Primate&amp;#x2019;s superclass (Object)
  81. Missing Primate&amp;#x2019;s superclass (Object)
  82. Missing Primate&amp;#x2019;s superclass (Object)
  83. Missing Primate&amp;#x2019;s superclass (Object)
  84. Missing Primate&amp;#x2019;s superclass (Object)
  85. Missing Primate&amp;#x2019;s superclass (Object)
  86. Missing Primate&amp;#x2019;s superclass (Object)
  87. we have part of ruby&amp;#x2019;s object model, lets continue by fixing a problem
  88. ruby creates singletons on-demand, but metaclasses automatically that includes object insert object into graph
  89. added object&amp;#x2019;s metaclass object&amp;#x2019;s class methods will not be visible on primate Primate.inspect
  90. added object&amp;#x2019;s metaclass object&amp;#x2019;s class methods will not be visible on primate Primate.inspect
  91. added object&amp;#x2019;s metaclass object&amp;#x2019;s class methods will not be visible on primate Primate.inspect
  92. added object&amp;#x2019;s metaclass object&amp;#x2019;s class methods will not be visible on primate Primate.inspect
  93. added object&amp;#x2019;s metaclass object&amp;#x2019;s class methods will not be visible on primate Primate.inspect
  94. added object&amp;#x2019;s metaclass object&amp;#x2019;s class methods will not be visible on primate Primate.inspect
  95. added object&amp;#x2019;s metaclass object&amp;#x2019;s class methods will not be visible on primate Primate.inspect
  96. Class has a metaclass too, but it&amp;#x2019;s pretty much limited to new Primate.foo inherits from Object the metaclass of my superclass is the superclass of my metaclass
  97. Class has a metaclass too, but it&amp;#x2019;s pretty much limited to new Primate.foo inherits from Object the metaclass of my superclass is the superclass of my metaclass
  98. Class has a metaclass too, but it&amp;#x2019;s pretty much limited to new Primate.foo inherits from Object the metaclass of my superclass is the superclass of my metaclass
  99. Class has a metaclass too, but it&amp;#x2019;s pretty much limited to new Primate.foo inherits from Object the metaclass of my superclass is the superclass of my metaclass
  100. Class has a metaclass too, but it&amp;#x2019;s pretty much limited to new Primate.foo inherits from Object the metaclass of my superclass is the superclass of my metaclass
  101. Class has a metaclass too, but it&amp;#x2019;s pretty much limited to new Primate.foo inherits from Object the metaclass of my superclass is the superclass of my metaclass
  102. Class has a metaclass too, but it&amp;#x2019;s pretty much limited to new Primate.foo inherits from Object the metaclass of my superclass is the superclass of my metaclass
  103. Class has a metaclass too, but it&amp;#x2019;s pretty much limited to new Primate.foo inherits from Object the metaclass of my superclass is the superclass of my metaclass
  104. what about module?
  105. ruby trickery with joe&amp;#x2019; superclass look at the diagram, what is Joe&amp;#x2019;s singleton&amp;#x2019;s superclass? including a module inserts it into the inheritance chain
  106. mention method_missing
  107. ruby hides it, but we can get it out
  108. ruby 1.8 only and does not effect method dispatch
  109. iclass code redacted ruby 1.8 only
  110. you can take singleton_class
  111. whenever you def object.method, you define a method on the singleton of that object
  112. class &lt;&lt; just switches into the context of the singleton class of whatever object you specify
  113. &lt;&lt; = &amp;#x201C;give me ur singleton class&amp;#x201D; switches into the context of the singleton class of self