Slide 1

Slide 1 text

variable scope in ruby a techno-preso-blogpost 16.10.13 charlotte chang

Slide 2

Slide 2 text

first, the preamble the hardest thing about writing anything is the examples. ...picking good examples carries a book, right? If the examples are bad, you hate them. If the examples are engaging...they teach you the right things, then they keep your attention. -sandy metz Ruby Rogues

Slide 3

Slide 3 text

many myriad missive mischievous multifarious massive multitudinous macabre mayhem merry magnificent marauding Mixed Metaphors

Slide 4

Slide 4 text

Part I. mini journey into the veritable variable

Slide 5

Slide 5 text

Variables are like nicknames. Remember when everyone used to call you Stinky Pete? People would say, “Get over here, Stinky Pete!” And everyone miraculously knew that Stinky Pete was you." -Why’s Poignant Guide to Ruby

Slide 6

Slide 6 text

plain lowercase words can include letters, digits and _ syntax kale fat_puggle fly_hitops snuggie sarcasm _8tracks pink_scrunchie accordion bear_trap

Slide 7

Slide 7 text

something you want to use frequently && you don’t want to type it over and over and over and over and over and over and over and over and over and over and over over ove why?

Slide 8

Slide 8 text

something you want to use frequently this is a function but it could be... else?

Slide 9

Slide 9 text

beaker beaker these are variables where you could put

Slide 10

Slide 10 text

beaker beaker 6 * volume(beaker) == 2 * volume(beaker)

Slide 11

Slide 11 text

1 * volume(beaker)

Slide 12

Slide 12 text

variables can be named anything you want but they should be relevant and by the way, naming your variables with the same name is a bad idea.

Slide 13

Slide 13 text

types of variables global $ instance @ or self. local [a-z] or _ constant [A-Z] class @@

Slide 14

Slide 14 text

Part II. How I Learned to Stop Worrying and Love the Ruling Class

Slide 15

Slide 15 text

newb’s journey into variable scope 5.steps do | easy | .hold

Slide 16

Slide 16 text

newb’s journey into variable scope 5.steps do | easy | 1 5 Bourgeoisie Obamacare

Slide 17

Slide 17 text

newb’s journey into variable scope 5.steps do | easy | 1 2 3 4 5 Bourgeoisie BenevolentBourgeoisie Canada OnePercent Obamacare

Slide 18

Slide 18 text

1

Slide 19

Slide 19 text

can the baker use the brewmaster’s tools? can the carpenter use the baker’s bandages? local variable scope 1

Slide 20

Slide 20 text

what do you notice about the medicine(s)? local variable scope 1

Slide 21

Slide 21 text

DRY Don’t Repeat Yourself The Pragmatic Programmer Andy Hunt and Dave Thomas 1

Slide 22

Slide 22 text

2

Slide 23

Slide 23 text

2 class instance variable scope who has the medicine? who can use the medicine? when is medicine used?

Slide 24

Slide 24 text

Do one thing. curly’s law 2

Slide 25

Slide 25 text

3

Slide 26

Slide 26 text

3 constant scope when would the brewmaster get medicine? when would the brewmaster go to the doctor?

Slide 27

Slide 27 text

3 constant scope who has to use wait_time? when/how does the brewmaster have to wait_time?

Slide 28

Slide 28 text

3 constant scope what if there was a wait for beer? next year, the wait time increases to 10 weeks, what happens?

Slide 29

Slide 29 text

3 No magic numbers. Steve McConnell

Slide 30

Slide 30 text

4

Slide 31

Slide 31 text

4 class variable scope do the brewmaster and the carpenter go to the same doctor? can the doctor prescribe medicine independent of a pharmaceutical company? if a doctor gets sued, where can s/he get money from?

Slide 32

Slide 32 text

4 Class instance variables should usually be preferred over class variables. Github's Ruby Styleguide

Slide 33

Slide 33 text

5

Slide 34

Slide 34 text

5 global variable scope who can access healthcare? can new instances of America have healthcare? does America know where healthcare comes from?

Slide 35

Slide 35 text

1. what is a variable? 2. what are the types of variables? 3. what is variable scope? 4. what are the types of variable scope? recap 1 2 3 4 5 Bourgeoisie BenevolentBourgeosie Canada OnePercent Obamacare local class instance constant class global

Slide 36

Slide 36 text

<%= some_witty_ending %>