# Here is how you could initialize a set of tweets from Dumbledore with a Hash.
# The hash key is the user name (dumbledore) appended with a sequential integer
# number that we will start at 1. The combination of the user name
# and the next integer number provide a unique hash key for each Tweet.
dumbledore = {
"dumbledore1" => "Happy birthday Fawkes! Not sure what I'd do without your firey personality in my life. ;-D",
"dumbledore2" => "Please join us for, 'Hogwarts against the Dark Arts' benefit at the Quiddich Trillenium Stadium this Saturday!",
"dumbledore3" => "Put a drink it my cup, fill it up, fill it up! Liquid Luck in my cup, fill it up, fill it up!",
"dumbledore4" => "Happiness can be found even in the darkest of times, if one only remembers to turn on the light.",
"dumbledore5" => "@HarryPotter, where is your invisibility cloak? I can't seem to find it. XD",
}
# Let's print our Tweets ... I put the key between parentheses to make it stand out
printf "Dumbledore's latest tweets: \n\n"
dumbledore.each { |key, val| puts "(#{key}) #{val}" }
# Now let us set up our hash of Tweets for the Voldemort.
# Similar to the dumbledore hash, let's initialize our hash of Tweets for the Voldemort.
voldemort = {
"voldemort1" => "Kind of freaking out, because I can't remember for the life of me where I put one of my horcrux's...",
"voldemort2" => "May I kindly remind whoever else is considering tweeting about my nose that I am, indeed, master of the dark arts. Anything else you would like to comment on?",
"voldemort3" => "Skkkahssss shaahsssstttt. That's parseltoungue for, 'I couldn't care less.' ",
"voldemort4" => "Don't you just love the smell of a freshly stolen wand?",
"voldemort5" => "Just a reminder: Only I can live forever."
}
# Here is how you could add to our Hash - just make sure your hash key is unique
voldemort ["voldemort6"] = "Nagini far surpasses the intelligence and companionship of your little fire parrot, @dumbledore."
voldemort ["voldemort7"] = "There is no good and evil. There is only power, and those too weak to seek it."
voldemort ["voldemort8"] = "From this day forth, you put your faith in me."
# Over time, you would like a way to automatically generate a unique hash key. Here I set
# up a variable called volnum where I can increment it by 1 each time and append it to the string
# "voldemort" to form a unique key ... in this case, our hash key is now: "voldemort9"
volnum = 8
volnum = volnum + 1 # volnum is now 9
nextKey = "voldemort" + volnum.to_s() # convert volnum value to a string, and nextKey is now "voldemort9"
# Use our unique hash key (nextKey) to create a new Tweet in our hash
voldemort [nextKey] = "@harrypotter You have allowed your friends to die for you rather than face me yourself!"
# I could do this over and over again so it is automatically done each time Batman sends a new tweet.
# Here is another round ... but as a challenge, could you create a function that might add a
# given tweet to the hash with a next sequential unique key?
volnum +=1; # another way to increment volnum by 1, volnum is now 10
nextKey = "voldemort" + volnum.to_s() # nextKey is now "voldemort10"
# Here is another tweet added to our hash
voldemort [nextKey] = " *Points at Mondays* Avada Kedavra!"
# Let's print out all the Tweets from the Voldemort
printf "\n\nA few darker tweets from Voldemort (a.k.a., the Dark Lord): \n\n"
voldemort.each { |key, val| puts "(#{key}) #{val}" }