15/16 Am I thinking about literal and implicit Hash notations correctly?


Got the green-light, but I guess I'm just wondering if the key follows the value with implicit (Hash.new) format compared to literal, where the key => value? My code is below, and I'm curious if this is a proper comparison of literal and implicit Hash notation:

my_hash = {
    "cat" => "Garfield",
    "cat" => "Gnar",
    "cat" => "Fraggle Batches",
    "dog" => "Dumper",
    "dog" => "Argos",
    "dog" => "Midas"

# Or:

my_hash = Hash.new
my_hash["Garfield"] = "cat"
my_hash["Gnar"] = "cat"
my_hash["Fraggle Batches"] = "cat"
my_hash["Dumper"] = "dog"
my_hash["Argos"] = "dog"
my_hash["Midas"] = "dog"


You have the same exact same key pointing to different values.

Typically, you use hashes with the opposite behavior: you can have multiple keys pointing to the same value.

Your second section does not match the first -- you switched the key and values around.

But your section section reflects proper hash usage.

In conclusion, your first section should be changed to

   my_hash = {
         "Garfield" => "cat",
             "Gnar" => "cat",

So that your get proper behavior. It is always Key => Value

Keys mapped to values!!