Upcoming SlideShare
×

ChrisPine_UROM.ppt

561 views

Published on

Published in: Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
561
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
6
0
Likes
0
Embeds 0
No embeds

No notes for slide

ChrisPine_UROM.ppt

1. 1. Understanding Ruby’s Object Model Chris Pine July 10, 2003
2. 2. Some Ruby Basics <ul><li>1234567.class  Fixnum </li></ul><ul><li>' hello ' .class  String </li></ul>
3. 3. Some Ruby Basics <ul><li>1234567.class  Fixnum </li></ul><ul><li>' hello ' .class  String </li></ul><ul><li>Fixnum.superclass  Integer </li></ul><ul><li>String.superclass  Object </li></ul>
4. 4. Some Ruby Basics <ul><li>1234567.class  Fixnum </li></ul><ul><li>' hello ' .class  String </li></ul><ul><li>Fixnum.superclass  Integer </li></ul><ul><li>String.superclass  Object </li></ul><ul><li>' hello ' .kind_of?(String)  true </li></ul><ul><li>1234567.kind_of?(Integer)  true </li></ul><ul><li>1234567.kind_of?(String)  false </li></ul>
5. 5. A Little Quiz <ul><li>Object.kind_of?(Object)  ? </li></ul>
6. 6. A Little Quiz <ul><li>Object.kind_of?(Object)  true </li></ul><ul><li>Object.kind_of?(Class)  ? </li></ul>
7. 7. A Little Quiz <ul><li>Object.kind_of?(Object)  true </li></ul><ul><li>Object.kind_of?(Class)  true </li></ul><ul><li>Class.kind_of?(Object)  ? </li></ul>
8. 8. A Little Quiz <ul><li>Object.kind_of?(Object)  true </li></ul><ul><li>Object.kind_of?(Class)  true </li></ul><ul><li>Class.kind_of?(Object)  true </li></ul><ul><li>Class.kind_of?(Class)  ? </li></ul>
9. 9. A Little Quiz <ul><li>Object.kind_of?(Object)  true </li></ul><ul><li>Object.kind_of?(Class)  true </li></ul><ul><li>Class.kind_of?(Object)  true </li></ul><ul><li>Class.kind_of?(Class)  true </li></ul><ul><li>' hey ' .kind_of?(String)  ? </li></ul>
10. 10. A Little Quiz <ul><li>Object.kind_of?(Object)  true </li></ul><ul><li>Object.kind_of?(Class)  true </li></ul><ul><li>Class.kind_of?(Object)  true </li></ul><ul><li>Class.kind_of?(Class)  true </li></ul><ul><li>' hey ' .kind_of?(String)  true </li></ul><ul><li>String.kind_of?(Class)  ? </li></ul>
11. 11. A Little Quiz <ul><li>Object.kind_of?(Object)  true </li></ul><ul><li>Object.kind_of?(Class)  true </li></ul><ul><li>Class.kind_of?(Object)  true </li></ul><ul><li>Class.kind_of?(Class)  true </li></ul><ul><li>' hey ' .kind_of?(String)  true </li></ul><ul><li>String.kind_of?(Class)  true </li></ul><ul><li>Fixnum.kind_of?(Integer)  ? </li></ul>
12. 12. A Little Quiz <ul><li>Object.kind_of?(Object)  true </li></ul><ul><li>Object.kind_of?(Class)  true </li></ul><ul><li>Class.kind_of?(Object)  true </li></ul><ul><li>Class.kind_of?(Class)  true </li></ul><ul><li>' hey ' .kind_of?(String)  true </li></ul><ul><li>String.kind_of?(Class)  true </li></ul><ul><li>Fixnum.kind_of?(Integer)  false </li></ul>
13. 13. Wrong Mental Picture Object class Classes Subclasses objects
14. 14. What We Know… <ul><li>aClass.superclass.superclass… </li></ul><ul><li> Object </li></ul><ul><li>Object.superclass  nil </li></ul>
15. 15. What We Know… <ul><li>aClass.superclass.superclass… </li></ul><ul><li> Object </li></ul><ul><li>Object.superclass  nil </li></ul><ul><li>anObject.class.class…  Class </li></ul><ul><li>Class.class  Class </li></ul>
16. 16. What We Know… <ul><li>aClass.superclass.superclass… </li></ul><ul><li> Object </li></ul><ul><li>Object.superclass  nil </li></ul><ul><li>anObject.class.class…  Class </li></ul><ul><li>Class.class  Class </li></ul><ul><li>aClass.class  Class </li></ul><ul><li>anObject.class.class  Class </li></ul>
17. 17. Superclass Relationships Object Module Class String Integer Fixnum
18. 18. Class Relationships Object Module String Integer Fixnum 5 ' hi ' Class
19. 19. Relationships <ul><li>anObject.class </li></ul><ul><li>aClass.superclass </li></ul><ul><li>anObject.kind_of? </li></ul>*
20. 20. Right Mental Picture Object Module Class String Integer Fixnum 5 ' hi '
21. 21. Modules <ul><li>module FooMod class String </li></ul><ul><li>def foo include FooMod </li></ul><ul><li>' BIGFOO! ' end </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>Object Proxy: FooMod foo String reverse split …
22. 22. Singleton Classes (objects) <ul><li>me = ' Chris ' </li></ul><ul><li>def me.wife </li></ul><ul><li>' Katy ' </li></ul><ul><li>end </li></ul>String 'Chris'(S) ' Chris ' reverse split … wife
23. 23. Singleton Classes (classes) <ul><li>poly = Polygon.new </li></ul><ul><li>poly.area  12.823 </li></ul><ul><li>Polygon.largest  poly </li></ul><ul><li>tri = Triangle.new </li></ul><ul><li>tri.area  9.816 </li></ul><ul><li>tri.hypotenuse  7.244 </li></ul><ul><li>Triangle.largest  tri </li></ul>
24. 24. Singleton Classes (classes) Polygon Triangle hypotenuse area largest new Class Polygon(S) ? ? ? ?
25. 25. Polygon Triangle hypotenuse area largest new Class Poly(S) Tri(S) Object Obj(S) Class(S) Mod(S) Module