# Assignment 9 - Tweeting with Ruby
# J Student
# Here is how you could initialize a set of tweets from Einstein with a Hash.
# The hash key is the user name (einstein) 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.
einstein = {
"einstein1" => "Imagination is more important than knowledge.",
"einstein2" => "Life is like riding a bicycle. To keep your balance you must keep moving.",
"einstein3" => "Try not to become a man of success, but rather try to become a man of value.",
"einstein4" => "The important thing is not to stop questioning.",
"einstein5" => "I have no special talents. I am only passionately curious.",
"einstein6" => "Reality is merely an illusion, albeit a very persistent one."
}
# Let's print our Tweets ... I put the key between parentheses to make it stand out
printf "A few thoughtful tweets from Albert Einstein:\n\n"
einstein.each { |key, val| puts "(#{key}) #{val}" }
# Now let us set up our hash of Tweets for Yoda ... the wise Jedi Master ...
# Similar to the Einstein hash, let's initialize our hash of Tweets for Yoda.
yoda = {
"yoda1" => "Do or do not. There is no try.",
"yoda2" => "Train yourself to let go of everything you fear to lose.",
"yoda3" => "Fear is the path to the dark side.",
"yoda4" => "In a dark place we find ourselves, and a little more knowledge lights our way.",
"yoda5" => "Truly wonderful, the mind of a child is."
}
# Here is how you could add to our Hash - just make sure your hash key is unique
yoda["yoda6"] = "The greatest teacher, failure is."
# Over time, you would like a way to automatically generate a unique hash key. Here I set
# up a variable called yodanum where I can increment it by 1 each time and append it to the string
# "yoda" to form a unique key ... in this case, our hash key is now: "yoda7"
yodanum = 6
yodanum += 1 # yodanum is now 7
nextKey = "yoda" + yodanum.to_s() # convert yodanum value to a string, nextKey is "yoda7"
# Use our unique hash key (nextKey) to create a new Tweet in our hash
yoda[nextKey] = "Pass on what you have learned. Strength, mastery, but weakness, folly, failure also."
# We can add another one as well
yodanum += 1 # yodanum is now 8
nextKey = "yoda" + yodanum.to_s()
yoda[nextKey] = "Size matters not. Look at me. Judge me by my size, do you?"
# Let's print out all the Tweets from Yoda
printf "\n\nA few wise tweets from Master Yoda:\n\n"
yoda.each { |key, val| puts "(#{key}) #{val}" }