Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Variable Scope in Ruby

Variable Scope in Ruby

an intro into variables and variable scope

glamouracademy

October 18, 2013
Tweet

More Decks by glamouracademy

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. plain lowercase words can include letters, digits and _ syntax

    kale fat_puggle fly_hitops snuggie sarcasm _8tracks pink_scrunchie accordion bear_trap
  4. 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?
  5. 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.
  6. types of variables global $ instance @ or self. local

    [a-z] or _ constant [A-Z] class @@
  7. newb’s journey into variable scope 5.steps do | easy |

    1 2 3 4 5 Bourgeoisie BenevolentBourgeoisie Canada OnePercent Obamacare
  8. 1

  9. can the baker use the brewmaster’s tools? can the carpenter

    use the baker’s bandages? local variable scope 1
  10. 2

  11. 2 class instance variable scope who has the medicine? who

    can use the medicine? when is medicine used?
  12. 3

  13. 3 constant scope when would the brewmaster get medicine? when

    would the brewmaster go to the doctor?
  14. 3 constant scope what if there was a wait for

    beer? next year, the wait time increases to 10 weeks, what happens?
  15. 4

  16. 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?
  17. 5

  18. 5 global variable scope who can access healthcare? can new

    instances of America have healthcare? does America know where healthcare comes from?
  19. 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