SlideShare a Scribd company logo
1 of 68
Ruby object model
Javier Lafora
    Working at ASPgems
          @eLafo
elafosobrerailes.blogspot.com
In ruby everything is an object
object

flags
klass
instance_variables
MyClass

flags
klass
super
instance_variables
constants
methods
RBasic
                           RClass



        RObject
                          MyClass

                     flags
                     klass
        object       instance_variables
                     super
flags
klass
                     constants
instance_variables   methods
BasicObject
                       *super
                        *klass



                   Object        Module
                       *super        *super
                        *klass       *klass



                  Musician
                       *super
                        *klass
                      name=()
                       name()
                                  Class
                                      *super
                                      *klass

   bruce
                 IronMaiden
        *klass         *super
@name=”bruce”           *klass
Every instance of RClass will be an instance of Class



                  even Class itself
Unshamesly taken from Burkey Libbey's presentation
“Ruby's Object Model: Metaprogramming and other Magic”
BasicObject
                       *super
                        *klass



                   Object
                       *super
                        *klass



                  Musician
                       *super
                        *klass
                      name=()
                       name()




   bruce
                 IronMaiden
        *klass         *super
@name=”bruce”           *klass
BasicObject
                       *super
                        *klass



                   Object
                       *super
                        *klass
                        to_s()




                  Musician
                       *super
                        *klass




   bruce
                 IronMaiden
        *klass         *super
@name=”bruce”           *klass
Extending an object
SINGLETON CLASSES
bruce
                              IronMaiden
    *klass
                                    *super
             #bruce                 *klass

                    *klass
                    *super
             flight_plane()
Class Methods
Musician                            Class
     *super                             *super
     *klass                             *klass




              #Musician
                         *super
                          *klass
              awesome_musicians()
FAIL
Object
      *super                          Module
                                       Class
      *klass                              *super
                                          *klass

                #Musician
                           *super
Musician                    *klass
      *super    awesome_musicians()

      *klass




IronMaiden           Class
      *super               *super

       *klass               *klass
BasicObject     #BasicObject
      *super            *super
       *klass           *klass



  Object          #Object
      *super            *super
       *klass           *klass


                                 Class
                                     *super
 Musician       #Musician
                                     *klass
      *super           *super
       *klass          *klass




IronMaiden      #IronMaiden

      *super           *super
       *klass          *klass
“The superclass of the eigenclass of an object
is the object's class. The superclass of the
eigenclass of a class is the eigenclass of the
class's superclass.”

                                 Paolo Perrotta
Modules and mixins
IronMaiden
                                               *super
                                               *klass




                ICSinger
                          *super
                           *klass
             high_pitch_from_hell()


                                      #bruce
                                          *klass
bruce                                     *super
    *klass
Musician
                          *super
                           *klass


                                      ICHeavyMetal
                                               *super
                                                *klass
               IronMaiden                 devil_horns()


                          *super
                           *klass



                  #bruce
                            *klass
                           *super


                ICSinger
                          *super
bruce                      *klass
    *klass   high_pitch_from_hell()
ICHeavyMetal                      HeavyMetal
       *super                           *klass
       *klass                            *iv_tbl

        *iv_tbl                          *m_tbl

        *m_tbl
                  iv_tbl




                  m_tbl
                  devil_horns()
Object          #Object
       *super           *super
       *klass           *klass
        m_tbl            m_tbl



 Musician        #Musician
       *super           *super
       *klass           *klass
        m_tbl            m_tbl


ICHeavyMetal     HeavyMetal      #HeavyMetal
       *super           *super          *super
       *klass           *klass          *klass
        *m_tbl          *m_tbl          *m_tbl




IronMaiden       #IronMaiden
       *super           *super
       *klass           *klass
        *m_tbl          *m_tbl
Object                                   #Object




  Musician                                  #Musician




ICHeavyMetal       HeavyMetal


 ICHeavyMetal::     HeavyMetal::
InstanceMethods   InstanceMethods



                            HeavyMetal::
                            ClassMethods



                           ICHeavyMetal::
 IronMaiden                 ClassMethods
                                            #IronMaiden
Metaprogramming with Ruby – Paolo Perrotta


                http://mwrc2008.confreaks.com/11farley.html


     http://www.rubyinside.com/a-look-into-rubys-object-model-3940.html


                          http://rhg.rubyforge.org/


http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html


     http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html


    http://www.atalon.cz/rb-om/ruby-object-model/#sc-inheritance-sample
Thank you

More Related Content

Recently uploaded

Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 

Recently uploaded (20)

WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
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
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
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...
 

Ruby object model: A matter of life and death

  • 2. Javier Lafora Working at ASPgems @eLafo elafosobrerailes.blogspot.com
  • 3. In ruby everything is an object
  • 4.
  • 5.
  • 6.
  • 9. RBasic RClass RObject MyClass flags klass object instance_variables super flags klass constants instance_variables methods
  • 10.
  • 11.
  • 12.
  • 13. BasicObject *super *klass Object Module *super *super *klass *klass Musician *super *klass name=() name() Class *super *klass bruce IronMaiden *klass *super @name=”bruce” *klass
  • 14. Every instance of RClass will be an instance of Class even Class itself
  • 15. Unshamesly taken from Burkey Libbey's presentation “Ruby's Object Model: Metaprogramming and other Magic”
  • 16. BasicObject *super *klass Object *super *klass Musician *super *klass name=() name() bruce IronMaiden *klass *super @name=”bruce” *klass
  • 17. BasicObject *super *klass Object *super *klass to_s() Musician *super *klass bruce IronMaiden *klass *super @name=”bruce” *klass
  • 19.
  • 20.
  • 21.
  • 23.
  • 24.
  • 25.
  • 26. bruce IronMaiden *klass *super #bruce *klass *klass *super flight_plane()
  • 27.
  • 28.
  • 29.
  • 31.
  • 32. Musician Class *super *super *klass *klass #Musician *super *klass awesome_musicians()
  • 33. FAIL
  • 34. Object *super Module Class *klass *super *klass #Musician *super Musician *klass *super awesome_musicians() *klass IronMaiden Class *super *super *klass *klass
  • 35.
  • 36.
  • 37.
  • 38. BasicObject #BasicObject *super *super *klass *klass Object #Object *super *super *klass *klass Class *super Musician #Musician *klass *super *super *klass *klass IronMaiden #IronMaiden *super *super *klass *klass
  • 39. “The superclass of the eigenclass of an object is the object's class. The superclass of the eigenclass of a class is the eigenclass of the class's superclass.” Paolo Perrotta
  • 41.
  • 42.
  • 43. IronMaiden *super *klass ICSinger *super *klass high_pitch_from_hell() #bruce *klass bruce *super *klass
  • 44.
  • 45.
  • 46. Musician *super *klass ICHeavyMetal *super *klass IronMaiden devil_horns() *super *klass #bruce *klass *super ICSinger *super bruce *klass *klass high_pitch_from_hell()
  • 47.
  • 48.
  • 49.
  • 50. ICHeavyMetal HeavyMetal *super *klass *klass *iv_tbl *iv_tbl *m_tbl *m_tbl iv_tbl m_tbl devil_horns()
  • 51.
  • 52.
  • 53.
  • 54. Object #Object *super *super *klass *klass m_tbl m_tbl Musician #Musician *super *super *klass *klass m_tbl m_tbl ICHeavyMetal HeavyMetal #HeavyMetal *super *super *super *klass *klass *klass *m_tbl *m_tbl *m_tbl IronMaiden #IronMaiden *super *super *klass *klass *m_tbl *m_tbl
  • 55.
  • 56. Object #Object Musician #Musician ICHeavyMetal HeavyMetal ICHeavyMetal:: HeavyMetal:: InstanceMethods InstanceMethods HeavyMetal:: ClassMethods ICHeavyMetal:: IronMaiden ClassMethods #IronMaiden
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67. Metaprogramming with Ruby – Paolo Perrotta http://mwrc2008.confreaks.com/11farley.html http://www.rubyinside.com/a-look-into-rubys-object-model-3940.html http://rhg.rubyforge.org/ http://www.madebydna.com/all/code/2011/06/24/eigenclasses-demystified.html http://www.ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html http://www.atalon.cz/rb-om/ruby-object-model/#sc-inheritance-sample

Editor's Notes

  1. Ruby C's VALUE type is interpreted as an integer, if it's (Fixnum, Symbol, true, false or nil), or a pointer, if it's a large value klass is always a large value
  2. struct st_table is mostly a ruby hash
  3. #define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k)) #define METACLASS_OF(k) RBASIC(k)->klass