Working with Hashes (2)

Exercise 8.1

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

languages = {
  :de => 'German',
  :en => 'English',
  :es => 'Spanish',
}
dictionary = {
  :de => { :one => 'eins', :two => 'zwei', :three => 'drei' },
  :en => { :one => 'one', :two => 'two', :three => 'three' },
  :es => { :one => 'uno', :two => 'dos', :three => 'tres' }
}

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

In German, eins means one, zwei means two, drei means three.
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:

de eins zwei drei
en one two three
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:

de eins zwei drei
en one  two  three
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:

| de | eins | zwei | drei  |
| en | one  | two  | three |
| es | uno  | dos  | tres  |

Show solution