Basics
a = {"one" => "111"} a.each_key {|key| if key == "one" then puts a.fetch(key) end}
How to set it up
b = { 1 => Proc.new do resize end, 2 => Proc.new do resize end, "one" => "111" }
Another way to set up your hash:
hash = {} hash["key"] = "value"
Duplicating a value:
hash = {} hash["key"] = "value" hash["duplicate"] = hash["key"]
Another way:
c = { 1 => "one", } d = { 2 => c[1], } c.merge!(d)
Another way to add to an existing hash:
a = { 1 => "one" } a.merge!({ 2 => "two" })
Calculate something as the key.
e_2 = 2 e = { 1 => "one", e_2 => "two", }
Generate the key intelligently:
f_2 = true f = { (if f_2 == true then 1 end) => "one", }
g_1 = false g = { (if g_1 == true then 1 else 2 end) => "test", }
h_1 = true h_2 = true h = { (if h_1 == true then 1 else nil end) => (if h_2 == true then "one" else nil end), 2 => "two" }
Resources ∞
Last updated 2019-11-16 at 05:42:07