Error in reading YAML

hi guys I am trying to read the YAML documents however it is giving me
error.

My YAML file is as below
scenario:noPassword
username:gaurang
password:
scenario:noUsername
username:
password:gaurang

And ruby file in which I am reading is like this
require 'yaml'

class ReadData
config = YAML.load_file("data.yaml")
  p config["noPassword"]["username"]
  p config["noPassword"]["password"]

end

When i run the above class it gives me following error.
undefined method `[]' for nil:NilClass (NoMethodError)

Any idea why I am getting this error ???

···

--
Posted via http://www.ruby-forum.com/.

You need to put a space after the : in your YAML file, otherwyse they won't be
recognized correctly. Try doing a

p config
p config.keys
p config.values

and you'll see what I'm talking about.

I hope this helps

Stefano

···

On Monday 01 August 2011 15:26:45 Gaurang Shah wrote:

hi guys I am trying to read the YAML documents however it is giving me
error.

My YAML file is as below
scenario:noPassword
username:gaurang
password:
scenario:noUsername
username:
password:gaurang

And ruby file in which I am reading is like this
require 'yaml'

class ReadData
config = YAML.load_file("data.yaml")
  p config["noPassword"]["username"]
  p config["noPassword"]["password"]

end

When i run the above class it gives me following error.
undefined method `' for nil:NilClass (NoMethodError)

Any idea why I am getting this error ???