Skip to content

Instantly share code, notes, and snippets.

@kingcons
Last active November 1, 2016 01:53
Show Gist options
  • Save kingcons/7fb55ecb0a8ed07cac6e to your computer and use it in GitHub Desktop.
Save kingcons/7fb55ecb0a8ed07cac6e to your computer and use it in GitHub Desktop.
Quiz 10/15

Section 1 - Top Level Code, Simple Block Usage

ages = [28, 32, 42, 64]
ages.map { |x| x * 2 }
ages.each { |age| puts "Age is: #{age}" }
  1. What is the result of the ages.map call? What about ages.each?

  2. Is x in scope during ages.each?

Section 2 - Functions, Parameters, and Hashes

days = { monday: 'energized',
         tuesday: 'excited',
         wednesday: 'resilient',
         thursday: 'exhausted',
         friday: 'drinking' }

def my_example(week)
  day = week.keys.sample
  feel = week[day]
  # feel = week.values.sample
  print_feels(feel)
end

def print_feels(stuff)
  puts "Today I'm feeling quite: #{stuff}"
end

my_example(days)
  1. What is the value of stuff in a call to print_feels?

Section 3 - Classes & Testing

  1. Where are instance variables visible/in scope?

  2. What is the purpose of unit tests?

  3. Can we call methods on a class anywhere we have an instance of that class?

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