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

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

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