1 of 99

Slide Notes

DownloadGo Live

Advanced Rails - Week 5

Published on Nov 21, 2015

No Description

PRESENTATION OUTLINE

ADVANCED RAILS

WEEK 5
Photo by JmZ Florent

WEEK 5

Photo by JmZ Florent

ANNOUNCEMENTS

Photo by jeffk

CODE REVIEW

HOMEWORK REVIEW

EMAIL, AUTHENTICATION, AUTHORIZATION

WTF IS WRONG WITH MY APP NOW?!

Photo by Travis Brown

SCOPE IS ONE OF 'EM

I GOT 99 PROBLEMS AND
Photo by Will Hastings

COMMON SCOPE ERRORS

Photo by Will Hastings

WTF IS SCOPE?

CONTEXT

FOR EXPRESSIONS
Photo by krossbow

LANGUAGE RULES

Photo by Stéfan

DIFFERENT RULES

DIFFERENT LANGUAGES HAVE

STATIC & DYNAMIC

TWO KINDS OF SCOPE RULES
Photo by JD Hancock

STATIC SCOPE

CONTEXT DETERMINED BEFORE RUN-TIME
Photo by DeathByBokeh

DYNAMIC SCOPE

CONTEXT DETERMINED AT RUN-TIME

FLEXIBLE

HAVING BOTH IS WHY RUBY FEELS SO
Photo by sitemarca

AND NATURAL

TO WRITE

RAILS WOULDN'T EXIST

WITHOUT RUBY'S SCOPE RULES
Photo by mdornseif

7 RUBY SCOPES

(PROBABLY MORE)
Photo by s58y

TODAY - 4 RUBY SCOPES

Photo by s58y

SOMEDAY

Photo by s58y

SLOWLY AND CAREFULLY

I'M GOING TO SPEAK
Photo by Praziquantel

QUESTIONS

RAISE YOUR HAND IF YOU HAVE
Photo by Gideon Tsang

READY?

CONSTANTS

FIRST SCOPE

CORE TO RUBY

UNIQUE RULES
Photo by Cee-Bee

LONG-TERM OBJECT STORAGE

LIKE OTHER LANGUAGES

NAMES FOR CLASS OR MODULE OBJECTS

UNLIKE OTHER LANGUAGES
Photo by Erik K Veland

UPPERCASE [A-Z]

BEGIN WITH AN

Use lexical scope

CONTEXT IS BOTH STATIC AND RELATIVE
Photo by Erik K Veland

NESTED IN THE OBJECT CLASS...

CONSTANTS ARE EITHER

OR NESTED IN ANOTHER CLASS OR MODULE

(ACTIVERECORD::BASE)
Photo by Lafinboy

DEMO

Photo by jun0ka

CONSTANTS REVIEW

Photo by jun0ka

CONSTANT SCOPE RULES

Photo by jun0ka

CURRENT CLASS

OR MODULE

EASIEST OF ALL SCOPES

PROMISE!
Photo by monkeyc.net

THE ONE BEING DEFINED

CURRENT CLASS OR MODULE IS
Photo by Wade Brooks

NEST OTHER DEFINITIONS

LET YOU
Photo by msSeason

NEST OTHER DEFINITIONS

Photo by msSeason

ACCESS CONTROL

METHODS HAVE SPECIAL RULES FOR
Photo by synx508

PUBLIC METHODS

LEAST ACCESS CONTROL
Photo by swh

CLASS IT'S DEFINED WITHIN

RECEIVER MUST BE AN INSTANCE OF THE
Photo by swh

PRIVATE METHODS

MOST ACCESS CONTROL
Photo by Andri8184

CURRENT OBJECT

RECEIVER MUST BE THE
Photo by Andri8184

PROTECTED METHODS

PICKY AS F*CK
Photo by quinet

CURRENT CLASS AND CURRENT OBJECT

RECEIVER'S CLASS MUST BE THE SAME AS THE
Photo by quinet

DEMO

Photo by VinothChandar

CURRENT CLASS REVIEW

Photo by VinothChandar

PUBLIC VS PRIVATE METHODS

Photo by VinothChandar

PUBLIC METHODS

Photo by VinothChandar

PRIVATE METHODS

Photo by VinothChandar

PROTECTED METHODS

Photo by VinothChandar

CURRENT OBJECT

THIRD SCOPE

CURRENT CLASS

VERY DIFFERENT CONCEPT THAN THE
Photo by normanack

SPECIAL VARIABLE

THAT REFERENCES THE CURRECT OBJECT
Photo by ericmay

SELF

ALWAYS THE CURRENT OBJECT

DEFAULT RECEIVER

FOR METHOD CALLS
Photo by ecstaticist

CHANGES AT RUN-TIME

2 SIMPLE RULES
Photo by kevin dooley

TWO WAYS TO CHANGE SELF

Photo by kevin dooley

DEMO

Photo by Adam Melancon

CURRENT OBJECT REVIEW

Photo by Adam Melancon

TWO WAYS TO CHANGE SELF

Photo by kevin dooley

VARIABLES

FOURTH AND LAST SCOPE FOR TODAY
Photo by ecstaticist

4 KINDS OF VARIABLES

Photo by ecstaticist

_ OR LOWERCASE [A-Z]

LOCAL VARIABLES
Photo by aspheric.lens

@

INSTANCE VARIABLES
Photo by Claudio.Ar

@@

CLASS VARIABLE

$

GLOBAL VARIABLE
Photo by Aztlek

ALMOST NEVER USED

CLASS AND GLOBAL VARIABLES ARE
Photo by tim caynes

ALMOST ALWAYS USED

LOCAL AND INSTANCE VARIABLES ARE
Photo by VinothChandar

LOCAL VARIABLES

SHORT-LIVED REFERENECES TO OBJECTS
Photo by aspheric.lens

LOCAL VARIABLE SCOPE

ISOLATED TO DECLARATION CONTEXT
Photo by SteveD.

FIRST ASSIGNMENT

DECLARATION MEANS
Photo by SteveD.

DECLARATION CONTEXT

Photo by SteveD.

DEMO

Photo by Al_HikesAZ

LOCAL VARIABLE REVIEW

Photo by Al_HikesAZ

INSTANCE VARIABLES

STORE OBJECT STATE
Photo by gnuckx

DIFFERENT STATE

ALLOWS OBJECTS OF THE SAME CLASS TO HAVE

NIL UNTIL DECLARED

Photo by Bert Kaufmann

#INITIALIZE

DECLARED WITHIN
Photo by Claudio.Ar

LAZY INITIALIZATION

WHEN NECESSARY
Photo by Claudio.Ar

THINK RAILS ACTIONS

Photo by Claudio.Ar

PUBLIC METHODS

OBSERVE AND ALTER WITH

LIVE INSIDE SELF

INSTANCES VARIABLES

DEMO

Photo by Claudio.Ar

INSTANCE VARIABLE REVIEW

Photo by Claudio.Ar

INSTANCE VARIABLE REVIEW

Photo by Claudio.Ar

END

NO MORE!
Photo by pj_vanf

WHAT'S THE POINT?

IT'S OKAY

IF YOU'RE STILL CONFUSED
Photo by PhotoJonny

HARD

RUBY SCOPES ARE
Photo by jbcurio

PRACTICE

GOING TO TAKE
Photo by alykat

FEEL CONFIDENT

UNITL YOU
Photo by Miss Yellow

UNTIL THEN...

USE ME

Photo by Monica's Dad

ASK QUESTIONS

Photo by photosteve101

SHOW ME YOUR CODE

I'LL BE GENTLE, I PROMISE
Photo by elliottcable

LAB SESSION

Photo by bkcasteel