Working with Hashes (2)

Exercise 8.1

Make a new file hashes_2-1.rb, and dd the following lines:

  1. languages = {
  2. :de => 'German',
  3. :en => 'English',
  4. :es => 'Spanish',
  5. }
  6. dictionary = {
  7. :de => { :one => 'eins', :two => 'zwei', :three => 'drei' },
  8. :en => { :one => 'one', :two => 'two', :three => 'three' },
  9. :es => { :one => 'uno', :two => 'dos', :three => 'tres' }
  10. }

Now, at the end of the file, add code that prints out the following:

  1. In German, eins means one, zwei means two, drei means three.
  2. In Spanish, uno means one, duo means two, tres means three.

Show solution

Exercise 8.2

Now, in a new file hashes_2-2.rb, with the same hashes from above, add code that prints out the following table:

  1. de eins zwei drei
  2. en one two three
  3. es uno dos tres

Show solution

Exercise 8.3

Copy your file to a new file cp hashes_2-2.rb hashes_2-3.rb and change your code so that it aligns the table columns:

  1. de eins zwei drei
  2. en one two three
  3. es uno dos tres

Show solution

Exercise 8.4

Copy your file to a new file cp hashes_2-3.rb hashes_2-4.rb and change your code so that it adds delimiters:

  1. | de | eins | zwei | drei |
  2. | en | one | two | three |
  3. | es | uno | dos | tres |

Show solution