Skip to content

Instantly share code, notes, and snippets.

@alexrothenberg
Created April 21, 2010 09:11
Show Gist options
  • Save alexrothenberg/373604 to your computer and use it in GitHub Desktop.
Save alexrothenberg/373604 to your computer and use it in GitHub Desktop.
# In DOS type
### cd \workshop
### mkdir ruby_exercises
### cd ruby_exercises
# Open the e editor
### e .
# Create a new file called hash_exercise.rb
###################################################
### EXERCISE 1
#Lookup in a hash
translation_hash = { :one => "un", :two => "deux", :three=> "trois" }
puts '### EXERCISE 1'
puts "1 is #{translation_hash[:one]}"
puts "2 is #{translation_hash[:two]}"
puts "50 is #{translation_hash[:fifty]}"
###################################################
### EXERCISE 2
#puts '### EXERCISE 2'
#puts "The numbers I know how to translate are #{translation_hash.keys}"
###################################################
### EXERCISE 3
#Make something fun
def use_kinyarwanda my_hash
my_hash[:one] = 'Rimwe'
my_hash[:two] = 'Kabiri'
my_hash[:three] = 'Gatatu'
end
#puts '### EXERCISE 3'
puts "In French: #{translation_hash}"
use_kinyarwanda(translation_hash)
puts "In Kinyarwanda: #{translation_hash}"
puts "1 is #{translation_hash[:one]}"
puts "2 is #{translation_hash[:two]}"
puts "50 is #{translation_hash[:fifty]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment