Skip to content

Instantly share code, notes, and snippets.

@mikedao
Created July 14, 2016 15:03
Show Gist options
  • Save mikedao/7ae5c2fee0b82b7fd533f7dfe4d599a2 to your computer and use it in GitHub Desktop.
Save mikedao/7ae5c2fee0b82b7fd533f7dfe4d599a2 to your computer and use it in GitHub Desktop.

Module 1 Week 3 Diagnostic.

  • What do we mean when we talk about a variable's "scope"?
  • Given the following code, what does the program output?
		def combine_variables(x)
		  puts "inner x is: #{x}"
		  puts "and outer b is: #{b}"
		end
		
		def b
		  12
		end
		
		a = 4
		combine_variables(a)
  • What is the value of hero after this code has executed?
		new_creatures = ["IntrepidDecomposedCyclist", "Dragon"]
		villain = "AssistantViceTentacleAndOmbudsman"
		hero = "who knows"
		
		new_creatures.each do |villain|
		  hero = "Dwemthy"
		  puts "this time the villain is #{villain} and the hero is #{hero}"
		end
  • What is a "handle" in terms of File I/O?

  • What is the difference between "w", "r", and "a" modes in File I/O?

  • Imagine we're writing software to model a Corgi dog. You don't need to write the implementation, but write a test for each of the following features:

  • A Corgi has a name.

  • A Corgi has an age.

  • A Corgi can lie down.

  • A Corgi can stand up.

  • A Corgi cannot lie down when already lying down.

  • A Corgi cannot stand when it is already standing.

  • A Corgi starts hungry.

  • A Corgi can eat, but only when it is hungry.

  • A Corgi is no longer hungry when it has eaten three times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment