SlideShare una empresa de Scribd logo
1 de 68
Descargar para leer sin conexión
Ruby object model
Javier Lafora
    Working at ASPgems
          @eLafo
elafosobrerailes.blogspot.com
In ruby everything is an object
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
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
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
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
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
SINGLETON CLASSES
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
bruce
                              IronMaiden
    *klass
                                    *super
             #bruce                 *klass

                    *klass
                    *super
             flight_plane()
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Class Methods
Ruby object model: A matter of life and death
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
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
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
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
IronMaiden
                                               *super
                                               *klass




                ICSinger
                          *super
                           *klass
             high_pitch_from_hell()


                                      #bruce
                                          *klass
bruce                                     *super
    *klass
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Musician
                          *super
                           *klass


                                      ICHeavyMetal
                                               *super
                                                *klass
               IronMaiden                 devil_horns()


                          *super
                           *klass



                  #bruce
                            *klass
                           *super


                ICSinger
                          *super
bruce                      *klass
    *klass   high_pitch_from_hell()
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
ICHeavyMetal                      HeavyMetal
       *super                           *klass
       *klass                            *iv_tbl

        *iv_tbl                          *m_tbl

        *m_tbl
                  iv_tbl




                  m_tbl
                  devil_horns()
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
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
Ruby object model: A matter of life and death
Object                                   #Object




  Musician                                  #Musician




ICHeavyMetal       HeavyMetal


 ICHeavyMetal::     HeavyMetal::
InstanceMethods   InstanceMethods



                            HeavyMetal::
                            ClassMethods



                           ICHeavyMetal::
 IronMaiden                 ClassMethods
                                            #IronMaiden
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
Ruby object model: A matter of life and death
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

Más contenido relacionado

Último

IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?Juan Carlos Gonzalez
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDELiveplex
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
100+ ChatGPT Prompts for SEO Optimization
100+ ChatGPT Prompts for SEO Optimization100+ ChatGPT Prompts for SEO Optimization
100+ ChatGPT Prompts for SEO Optimizationarrow10202532yuvraj
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
99.99% of Your Traces Are (Probably) Trash (SRECon NA 2024).pdf
99.99% of Your Traces  Are (Probably) Trash (SRECon NA 2024).pdf99.99% of Your Traces  Are (Probably) Trash (SRECon NA 2024).pdf
99.99% of Your Traces Are (Probably) Trash (SRECon NA 2024).pdfPaige Cruz
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 

Último (20)

IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?Governance in SharePoint Premium:What's in the box?
Governance in SharePoint Premium:What's in the box?
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDEADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
ADOPTING WEB 3 FOR YOUR BUSINESS: A STEP-BY-STEP GUIDE
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
100+ ChatGPT Prompts for SEO Optimization
100+ ChatGPT Prompts for SEO Optimization100+ ChatGPT Prompts for SEO Optimization
100+ ChatGPT Prompts for SEO Optimization
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
99.99% of Your Traces Are (Probably) Trash (SRECon NA 2024).pdf
99.99% of Your Traces  Are (Probably) Trash (SRECon NA 2024).pdf99.99% of Your Traces  Are (Probably) Trash (SRECon NA 2024).pdf
99.99% of Your Traces Are (Probably) Trash (SRECon NA 2024).pdf
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 

Destacado

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.pdfmarketingartwork
 
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
 

Destacado (20)

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...
 
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
 

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
  • 9. RBasic RClass RObject MyClass flags klass object instance_variables super flags klass constants instance_variables methods
  • 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
  • 26. bruce IronMaiden *klass *super #bruce *klass *klass *super flight_plane()
  • 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
  • 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
  • 43. IronMaiden *super *klass ICSinger *super *klass high_pitch_from_hell() #bruce *klass bruce *super *klass
  • 46. Musician *super *klass ICHeavyMetal *super *klass IronMaiden devil_horns() *super *klass #bruce *klass *super ICSinger *super bruce *klass *klass high_pitch_from_hell()
  • 50. ICHeavyMetal HeavyMetal *super *klass *klass *iv_tbl *iv_tbl *m_tbl *m_tbl iv_tbl m_tbl devil_horns()
  • 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
  • 56. Object #Object Musician #Musician ICHeavyMetal HeavyMetal ICHeavyMetal:: HeavyMetal:: InstanceMethods InstanceMethods HeavyMetal:: ClassMethods ICHeavyMetal:: IronMaiden ClassMethods #IronMaiden
  • 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

Notas del editor

  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