Wednesday, 15 August 2012

ruby - Array inside Hash - Some questions -



ruby - Array inside Hash - Some questions -

i have code:

a = {} a["first"] = [true, false] how can read "false"? tried: ["first"][2] output blank; how can check if ["second"] exist or if array length > 0? tried if a["second"] nil end or if a["second"].value.length>0 both seems incorrect; how can push/pop new "true" value within existing a["first"]'s array? how can delete a ["first"] index? (such a.pop["first"])

can help me?

ruby arrays 0 based elements 0 , 1; there not 2. use: a["first"][1]

a["second"].nil? true if there no "second" element of hash. utilize size array length, so: a["second"].size 1 time know "second" exists.

use: a["first"].push true

use: a["first"].pop

(a["first"] gets array; a lone hash made of 2 arrays.)

ruby arrays hash

No comments:

Post a Comment