Ich spiele mit verschachtelten Hashes herum. Aufgabe:Warum bekomme ich einen TypeError: keine implizite Umwandlung von Symbol in Integer?
Create three hashes called
person1
,person2
, andperson3
, with first and last names under the keys:first
and:last
. Then create a params hash so thatparams[:father]
isperson1
,params[:mother]
isperson2
, andparams[:child]
isperson3
. Verify that, for example,params[:father][:first]
has the right value.
Meine Lösung:
person1 = {first: "first_name1", last: "last_name1"}
person2 = {first: "first_name2", last: "last_name2"}
person3 = {first: "first_name3", last: "last_name3"}
params = { :father => ":person1", :mother => ":person2", :child => ":person3" }
dann params[:father][:first]
gibt
TypeError: no implicit conversion of symbol into Integer
Warum? Ich verstehe nicht, warum ich den TypeError bekomme.
Parameter Zugriffsschlüssel Wertepaar params = {: Vater => "person1",: mother => ": person2",: child => "person3"} und Zugriff params [: vater] geben Ergebnis "person1" –
Das ist verständlich. Es gab mehr als ein Argument, über das ich verwirrt war. – Savina10