• Like
  • Save
Ruby object model
Upcoming SlideShare
Loading in...5

Ruby object model






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Ruby object model Ruby object model Presentation Transcript

    • The Ruby Object Modela presentation for the Nashville Software School24 June, 2013
    • WHOAMI?● Max Beizer => jr. developer @ Centresource● NSS Cohort One graduate● maxbeizer on:○ twitter○ github○ irc
    • Credit Where Credit is Due...Practical Object-OrientedDesign in RubyMetaprogramming RubyPaolo PerrottaSandi Metz
    • Credit Where Credit is Due...Eliza Brockelizabrocksoftware.com
    • Ruby and ObjectsIn Ruby, everything is an object.** except when it isnt
    • see also: ancestors
    • Every Object "Returns to the Source"BasicObject
    • Why do I care?
    • Why do I care?Why does salutations respond to length and reverse, but not foo?
    • Remember:
    • ruby-doc.org -- String
    • ruby-doc.org -- Stringno love for foo:(
    • salutationssalutations.foo def fooend
    • salutationssalutations.foo def fooend
    • salutationssalutations.foo def fooendStringObjectBasicObjectdef fooenddef fooenddef fooend
    • salutationssalutations.foo def fooendStringObjectBasicObjectdef fooenddef fooenddef fooendNoMethodError
    • Impress Your Friends:Lookup what method_missing does.
    • salutationssalutations.foo def fooendStringObjectBasicObjectdef fooenddef fooenddef fooendNoMethodError+method_missing
    • This Guy Says:"Doesnt this make Ruby soooo much slowerthan #{my favorite compiled language}?"
    • My Retort:Moving on...
    • salutationssalutations.length def lengthend
    • salutationssalutations.length def fooendStringObjectBasicObjectdef lengthendsalutations.length == 13
    • Uncle Maxs Story Time...
    • Inheritanceor how I learned to stop worrying and love method lookup
    • A Simple Ruby Class: You
    • Its Alive!!!!!1
    • you == NSS Studentme != NSS Studenteliza != NSS Student
    • you == NSS Studentme == junior develiza == accomplished professional
    • YouMeElizaWe All Have:● name● experience● job(?)
    • Naïve Implementation(A.K.A. my middle names)D.R.Y. ?
    • Naïve Implementation(A.K.A. my middle names)D.R.Y.Sopping wet
    • Naïve Implementation(A.K.A. my middle names)What if the requirementschanged and "experience"were henceforth to be knownas "awesome_points" ...?What about specialization?Why have three classes thatdo the same thing?
    • Inheritance Is All About Commonality● Share common methods, attributes to keep it DRY● Generalization vs. Specialization● Abstract vs. Concreteuse the object model/lookup
    • SpecializationSame Method Name, Different ResultDifferent Methods
    • GeneralizationNssStudent is a ...?JrDev is a ...?AccomplishedProfessional is a ...?
    • it fits!!!!!!!1win
    • shared, generalized codeextracted/abstractedspecialized codecall to superinvokes the method in the super classoverrides the superclass
    • The Abstract Class in Inheritancepart of the lookup chaingenerally never to be instantiated on its own
    • Inheritance: is it right for you?Is it right for your problem set?Ask yourself: is this an isa?
    • Inheritance: is it right for you?Is it right for your problem set?caveat emptordeveloper-or
    • Inheritance: is it right for you?Is it right for your problem set?put another way: not everything is a nail
    • Rails-Colored Glasses
    • Way back when I was first learning Ruby(pause for laughter)Moduleswere all like:
    • NowadaysModulesare all like:
    • SoftWhere Co. App.
    • SoftWhere Co. App.
    • SoftWhere Co. App.
    • SoftWhere Co. App.Officeables methods become instancemethods for the Executive,MiddleManagement, and Developermodels.win
    • SoftWhere Co. App.All three methods have a single,authoritative place where they live.Thats D.R.Y.win
    • SoftWhere Co. App.not so muchWhat if I create anew class that needsto include Officeablebut I forget about ordont know aboutamount_of_unease???
    • SoftWhere Co. App.winThe next developerreceives a helpfulerror message.Novel concept.
    • SoftWhere Co. App.Side note: youll probably want to add a guard to make sureamount_of_unease is not zero.
    • A Rails Template PatternErich Gamma, Richard Helm, Ralph Johnson and John Vlissides
    • Make sure lib is in the load path
    • image credits:● http://www.newgre.org/admissions/applying-doctoral-programs-it%E2%80%99s-match/attachment/square-peg-in-a-round-hole/● amazon.com● elizabrocksoftware.com● http://www.hsxdude.com/● http://pragdave.pragprog.com/pragdave/2007/05/rails_is_love.html● http://creepypasta.wikia.com/wiki/File:Creepy-van.jpg● http://juliasetssail.blogspot.com/2010_04_01_archive.html● http://knowyourmeme.com/memes/haters-gonna-hate● http://blog.ausweb.com.au/system-administrator-appreciation-day/● http://worldtruth.tv/philosophy-the-matrix-return-to-the-source/the preceding presentation is intended for educational purposes only and should not be viewedby anyone anywhere, in perpetuity, throughout the universe