Ruby/Rails nested hash myhash[“key1”][“childkey”] - NoMethodError?

Because at the third line you're evaluating a json_hash'creditCard' which is nil then it has no method You can build an hash like that using json_hash = { "id" => 0,"creditCard" => { "address" => {"state" => "AZ"}}} and it has the given format Thats a short syntax, to specify the fact that what you want in json_hash it's NOT a single hash. It is an hash which has the value 0 in its id key, then in its creditCard it stores another hash which contains another hash (i. E {"state" => "AZ"} ) in its address key Look at this pry transcript: pry(main)> json_hash = { "id" => 0,"creditCard" => { "address" => {"state" => "AZ"}}} => {"id"=>0, "creditCard"=>{"address"=>{"state"=>"AZ"}}} pry(main)> json_hash.

Object_id => 2175368520 pry(main)> json_hash'creditCard'. Object_id => 2175368560 pry(main)> json_hash'creditCard''address'. Object_id => 2175368600 all these values have different object_id so they are not the same thing, neither property of the same thing.

Because at the third line you're evaluating a json_hash'creditCard' which is nil, then it has no method . You can build an hash like that using json_hash = { "id" => 0,"creditCard" => { "address" => {"state" => "AZ"}}} and it has the given format. Thats a short syntax, to specify the fact that what you want in json_hash it's NOT a single hash.It is an hash which has the value 0 in its "id" key, then in its "creditCard" it stores another hash which contains another hash (i.e.

{"state" => "AZ"}) in its "address" key. Look at this pry transcript: pry(main)> json_hash = { "id" => 0,"creditCard" => { "address" => {"state" => "AZ"}}} => {"id"=>0, "creditCard"=>{"address"=>{"state"=>"AZ"}}} pry(main)> json_hash. Object_id => 2175368520 pry(main)> json_hash'creditCard'.

Object_id => 2175368560 pry(main)> json_hash'creditCard''address'. Object_id => 2175368600 all these values have different object_id so they are not the same thing, neither property of the same thing.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions