DevHeads.net

Postings by Artie Ziff

Hash#update

Is there some reason that ruby-doc.org presents the merge method in the
example block for update method ?

<a href="https://ruby-doc.org/core-2.5.1/Hash.html#update-method" title="https://ruby-doc.org/core-2.5.1/Hash.html#update-method">https://ruby-doc.org/core-2.5.1/Hash.html#update-method</a>

thank you,
-az

Hash["string1, string2"]

Hello Ruby Friends!

I was reviewing Ruby docs and re-learned that a Hash can be created from
what appears to be a list of strings with the requirement that there is
even number.

I try it in irb:

irb(main):004:0> Hash["stringA1", "stringA2", "stringB1", "stringB2"]
=> {"stringA1"=>"stringA2", "stringB1"=>"stringB2"}

Yet when I try to automate it with a variable I see that the argument of
list appears to be unacceptable.

In irb:

irb(main):007:0> s = ["stringA1", "stringA2", "stringB1", "stringB2"]
=> ["stringA1", "stringA2", "stringB1", "stringB2"]
irb(main):008:0> Hash[s]
(irb):8: warni