Ruby object model
Javier Lafora    Working at ASPgems          @eLafoelafosobrerailes.blogspot.com
In ruby everything is an object
objectflagsklassinstance_variables
MyClassflagsklasssuperinstance_variablesconstantsmethods
RBasic                           RClass        RObject                          MyClass                     flags         ...
BasicObject                       *super                        *klass                   Object        Module             ...
Every instance of RClass will be an instance of Class                  even Class itself
Unshamesly taken from Burkey Libbeys presentation“Rubys Object Model: Metaprogramming and other Magic”
BasicObject                       *super                        *klass                   Object                       *sup...
BasicObject                       *super                        *klass                   Object                       *sup...
Extending an object
SINGLETON CLASSES
bruce                              IronMaiden    *klass                                    *super             #bruce      ...
Class Methods
Musician                            Class     *super                             *super     *klass                        ...
FAIL
Object      *super                          Module                                       Class      *klass                ...
BasicObject     #BasicObject      *super            *super       *klass           *klass  Object          #Object      *su...
“The superclass of the eigenclass of an objectis the objects class. The superclass of theeigenclass of a class is the eige...
Modules and mixins
IronMaiden                                               *super                                               *klass      ...
Musician                          *super                           *klass                                      ICHeavyMeta...
ICHeavyMetal                      HeavyMetal       *super                           *klass       *klass                   ...
Object          #Object       *super           *super       *klass           *klass        m_tbl            m_tbl Musician...
Object                                   #Object  Musician                                  #MusicianICHeavyMetal       He...
Metaprogramming with Ruby – Paolo Perrotta                http://mwrc2008.confreaks.com/11farley.html     http://www.rubyi...
Thank you
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
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
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
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
Upcoming SlideShare
Loading in …5
×

Ruby object model: A matter of life and death

1,807 views
1,747 views

Published on

Ruby object model internals for MRI. These slides have some animations, so if you want to see them all, you should download it. Created with libreoffice impress

0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,807
On SlideShare
0
From Embeds
0
Number of Embeds
21
Actions
Shares
0
Downloads
46
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide
  • 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
  • struct st_table is mostly a ruby hash
  • #define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k)) #define METACLASS_OF(k) RBASIC(k)->klass
  • Ruby object model: A matter of life and death

    1. 1. Ruby object model
    2. 2. Javier Lafora Working at ASPgems @eLafoelafosobrerailes.blogspot.com
    3. 3. In ruby everything is an object
    4. 4. objectflagsklassinstance_variables
    5. 5. MyClassflagsklasssuperinstance_variablesconstantsmethods
    6. 6. RBasic RClass RObject MyClass flags klass object instance_variables superflagsklass constantsinstance_variables methods
    7. 7. BasicObject *super *klass Object Module *super *super *klass *klass Musician *super *klass name=() name() Class *super *klass bruce IronMaiden *klass *super@name=”bruce” *klass
    8. 8. Every instance of RClass will be an instance of Class even Class itself
    9. 9. Unshamesly taken from Burkey Libbeys presentation“Rubys Object Model: Metaprogramming and other Magic”
    10. 10. BasicObject *super *klass Object *super *klass Musician *super *klass name=() name() bruce IronMaiden *klass *super@name=”bruce” *klass
    11. 11. BasicObject *super *klass Object *super *klass to_s() Musician *super *klass bruce IronMaiden *klass *super@name=”bruce” *klass
    12. 12. Extending an object
    13. 13. SINGLETON CLASSES
    14. 14. bruce IronMaiden *klass *super #bruce *klass *klass *super flight_plane()
    15. 15. Class Methods
    16. 16. Musician Class *super *super *klass *klass #Musician *super *klass awesome_musicians()
    17. 17. FAIL
    18. 18. Object *super Module Class *klass *super *klass #Musician *superMusician *klass *super awesome_musicians() *klassIronMaiden Class *super *super *klass *klass
    19. 19. BasicObject #BasicObject *super *super *klass *klass Object #Object *super *super *klass *klass Class *super Musician #Musician *klass *super *super *klass *klassIronMaiden #IronMaiden *super *super *klass *klass
    20. 20. “The superclass of the eigenclass of an objectis the objects class. The superclass of theeigenclass of a class is the eigenclass of theclasss superclass.” Paolo Perrotta
    21. 21. Modules and mixins
    22. 22. IronMaiden *super *klass ICSinger *super *klass high_pitch_from_hell() #bruce *klassbruce *super *klass
    23. 23. Musician *super *klass ICHeavyMetal *super *klass IronMaiden devil_horns() *super *klass #bruce *klass *super ICSinger *superbruce *klass *klass high_pitch_from_hell()
    24. 24. ICHeavyMetal HeavyMetal *super *klass *klass *iv_tbl *iv_tbl *m_tbl *m_tbl iv_tbl m_tbl devil_horns()
    25. 25. Object #Object *super *super *klass *klass m_tbl m_tbl Musician #Musician *super *super *klass *klass m_tbl m_tblICHeavyMetal HeavyMetal #HeavyMetal *super *super *super *klass *klass *klass *m_tbl *m_tbl *m_tblIronMaiden #IronMaiden *super *super *klass *klass *m_tbl *m_tbl
    26. 26. Object #Object Musician #MusicianICHeavyMetal HeavyMetal ICHeavyMetal:: HeavyMetal::InstanceMethods InstanceMethods HeavyMetal:: ClassMethods ICHeavyMetal:: IronMaiden ClassMethods #IronMaiden
    27. 27. 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
    28. 28. Thank you

    ×