h = {"apple" => "red"}
h.keys #=> ["apple"]
h.keys[0] # => "apple"
a = [1, [2, [3, [4, 5]]]]
a.flatten(1) #=> [1, 2, [3, [4, 5]]]
a.flatten(2) #=> [1, 2, 3, [4, 5]]
a.flatten(3) #=> [1, 2, 3, 4, 5]
a.flatten #=> [1, 2, 3, 4, 5]
h1 = {"red" => "apple"}
h2 = {"red" => "tomato"}
h1.merge(h2) #=> {"red"=>"tomato"}
h2.merge(h1) #=> {"red"=>"apple"}
As above, if the keys are the same, they will be overwritten by the hash value of the argument. merge can receive blocks as shown below, and can specify the behavior when the key is duplicated.
h1 = {"red" => "apple"}
h2 = {"red" => "tomato"}
h1.merge(h2){|key,h1v,h2v| "#{h1v}" + "," + "#{h2v}"}
#=> {"red"=>"apple,tomato"}
h = {"red" => "apple"}
h.key?("red") #=> true
h.has_key?("red") #=> true
h.key?("blue") #=> false
h.has_key?("blue")#=> false