I might be over thinking, Why is this?


#1

for some reason this code is right but i don't understand why. it's completly different in the example. i skipped the banana and apple bit.

The example code:
prices = { 
  "apple" => 0.52,
  "banana" => 0.23,
  "kiwi" => 1.42
}

sounds = Hash.new
sounds["dog"] = "woof"
sounds["cat"] = "meow"

my code:

my_hash = Hash.new
my_hash["dog"] = "woof"
my_hash["cat"] = "meow"


#2

In the example, there are showed two different methods for creating hash. You decided to use Hash.new. Please explain to me how this code (from example):

sounds = Hash.new
sounds["dog"] = "woof"
sounds["cat"] = "meow"

is completely different than your code:

my_hash = Hash.new
my_hash["dog"] = "woof"
my_hash["cat"] = "meow"

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.