Skip to content

Instantly share code, notes, and snippets.

@mattmarcello
Created October 3, 2014 14:54
Show Gist options
  • Save mattmarcello/144d107564595cb87c4b to your computer and use it in GitHub Desktop.
Save mattmarcello/144d107564595cb87c4b to your computer and use it in GitHub Desktop.

(1) Create a hash with the following key value pairs

key value
red green
yellow purple
blue orange
# your code here

(2) Change values in a hash.

Go from:

lemurs = {
  andrew: "for all intensive purposes",
  matt: "for all in tents and porpoises"
}

To:

{andrew: 'i am a lemur!', matt: 'i am a lemur, also'}

You do not need to use iteration here.

# your code here

(3)

Go from:

ramen_places = {
  'Mu Ramen' => '917-868-8903',
  'Ivan Ramen' => '212-582-7940',
  'Takashi' => '212-414-2929',
}

To:

Mu Ramen's phone number is 917-868-8903.
Ivan Ramen's phone number is 917-868-8903.
Takashi's phone number is 917-868-8903.
# put your code here

(4) Go from:

lyrics = {
  "boy" => "love",
  "you're" => "you",
  "going" => "take",
  "to" => "equals",
  "carry" => "love",
  "that" => "you",
  "weight" => "make"
}

To:

  ["boy", "you're", "going", "to", "carry", "that", "weight"]
# put your code here

(5)

To:

["love", "you", "take", "equals", "love", "you", "make"]
# put your code here

(6)

What will be the return value of the following expression. Attempt to answer without running this code.

hash = Hash.new
if hash[:thing]
  "The thing exists"
else
  "The thing does not exist"
end
# put your answer here

(7) What will be the return value of the following expression. Attempt to answer without running this code.

hash = Hash.new("gluten")
if hash[:food]
  "this probably has gluten in it, doesn't it?"
else
  "what even is a gluten?"
end
# put your answer here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment