Skip to content

Instantly share code, notes, and snippets.

@dijonkitchen
Created November 17, 2015 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dijonkitchen/1b04a851a2293333c193 to your computer and use it in GitHub Desktop.
Save dijonkitchen/1b04a851a2293333c193 to your computer and use it in GitHub Desktop.
Phase-1-Checkpoint
# User story:
# Use a built-in ruby structure for pets (name, type)
# Harry is a dog,
# Rufus is a cat,
# Jane is a chimp,
# Sally is a snake,
# Ernie is a chimp,
# Melvin is a hamster
pets = {"Harry"=>"dog",
"Rufus"=>"cat",
"Jane"=>"chimp",
"Sally"=>"snake",
"Ernie"=>"chimp",
"Melvin"=>"hamster"}
# Write a method to add a pet to the collection
def add_pet(name, type, pets)
pets[name] = type
end
# Use a method to list pets and type in console
def list_pets(pets)
puts pets
end
# Print pets in an ordered list
def ordered_pets(pets)
counter = 1
pets.each do |name, type|
puts "#{counter}. #{name} #{type}"
counter += 1
end
end
# User story: use a method to filter a collection by a type of pet and list only a certain type, show name and type
def filter_pets(filter,pets)
pets.each do |name, type|
if type == filter
puts "#{name} #{type}"
end
end
end
# Given your current data structure, how would you add an age
# I would change the values in the hash to an array that stores both it's type and age.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment