12/15 Hashes and Symbols - Syntax Error


#1

Trying to convert a hash rocket to 1.9 hash syntax and I can't see what I'm doing wrong...

movies = Hash.new
movies = { Django Unchained: "Starring Jamie Foxx",
Inglourious Basterds: "Starring Brad Pitt",
Pulp Fiction: "Starring Samuel L Jackson"
}

Error message says "Oops, try again. Did you create a variable called movies?"
(ruby):1: syntax error, unexpected tLABEL, expecting keyword_do or '{' or '('
movies = { Django Unchained: "Starring Jamie Foxx",
^
(ruby):1: syntax error, unexpected ',', expecting $end

Can anyone shed any light?


#2

either use hash literal notation

new_hash = { "one" => 1 }

or hash constructor notation:

new_hash = Hash.new

now you've mixed

and you can't have a space for key name if you use hash literal notation

go to that lesson where you learned about it


#3

So my hash rocket on 11/15 was as follows -
movies = {
:"Django Unchained" => "Starring Jamie Foxx",
:"Inglourious Basterds" => "Starring Brad Pitt",
:"Pulp Fiction" => "Starring Samuel L Jackson",
}

which worked but when I updated it to 1.9 hash syntax in 12/15 like this -

movies = {
Django Unchained: "Starring Jamie Foxx" ,
Inglourious Basterds: "Starring Brad Pitt" ,
Pulp Fiction: "Starring Samuel L Jackson"
}

it won't work... I'm sure I'm just being really slow, but I can't see what's wrong with it. I added 'Hash.new' as I thought that might be the problem...
Tried putting the key in quotations as well but that didn't work.


#4

so you can do Django_Unchained instead of Django Unchained

Also see this lesson for Hash.new


#5

the space!!! Thank you!