I am new in Ruby and I wanna add a block of hash to the top of the programmer_hash:
def adding_matz
programmer_hash =
{
:grace_hopper => {
:known_for => "COBOL",
:languages => ["COBOL", "FORTRAN"]
},
:alan_kay => {
:known_for => "Object Orientation",
:languages => ["Smalltalk", "LISP"]
},
:dennis_ritchie => {
:known_for => "Unix",
:languages => ["C"]
}
}
end
This is what I want to add to the top of programmer_hash hash:
:yukihiro_matsumoto => {
:known_for => "Ruby",
:languages => ["LISP", "C"]
}
I have added the code below at the end of the method:
programmer_hash[:yukihiro_matsumoto] = [:known_for['Ruby']]
programmer_hash[:yukihiro_matsumoto][:languages] = 'LISP'
programmer_hash[:yukihiro_matsumoto][:languages] = 'C'
It worked pretty well, but I want to do all of this in one line, but nothing comes out right. I will appreciate your help.
:known_for['Ruby']returnsnil, so the first line would assign[nil]to the key:yukihiro_matsumoto. The second line would then result in an error.