This is the notes we made while going through 1505's Object Model at Turing School. Unfortunately, we lost an hour and a whiteboard during Object Model 1, and had to change venues. Fortunately, we got to drink, and I got the first bit recorded.
A while back I made this quiz. I've completely changed the material since I gave this, but the takeaways are still the same.
I was able to record the first half of our lecture. Ideally we would have had 3 hours, not 2, and ideally the second half would have gotten recorded, but my hard drive filled up :(
I placed our notes in this repo, we'll keep building on them as we get more Object Models.
I added some challenges to this repo. Go through them using Seeing Is Believing like this:
- Uncomment the marked lines
- Predict what you think the answer will be
- Run them with Command+Option+n to verify
- If you got the answer wrong, stop and consider why.
- Did you miss something? Make a point to identify and notice it.
- Is there something you don't understand? Can you identify the disparity between what you expected happened?
...I don't actually care very much about the Object Model. It's mostly important because you're writing a lot of Ruby right now, and this is the underlying explanation that makes Ruby make sense. The real thing I want you to learn is the scientific method. Because with the scientific method, you can learn anything. Teaching myself the object model was where I learned the scientific method.
- Observe some behaviour.
- Hypothesize about what could explain it.
- Come up with an experiment to see if the explanation is correct.
- example: "If
self
is always the object we called the method on, then I could put a method in a superclass, andself
will be the instance of the subclass" - Run the experiment... I built you a labratory, and I try to illustrate how to use it as often as possible.
- Is the experiment correct? You are more confident in the hypothesis.
- Is the experiment incorrect? Go back to the first step :)
- example: "If
No one taught me the object model, I experimented my way into understanding over about 5 years (and then, years later learned C and verified that some of the crazier conclusions I'd reached were, in fact, correct, by reading Ruby's source code), and I continue to do this.
It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong.
Richard P. Feynman
Never believe anything you can't prove, even if I say it to you ;P