0

so writing hashes are straightforward, and it goes a little something like this...

  hash = { 'x'=>1, 'y'=>2, 'z'=>3 }

but there is another way to do so...

  hash_new[:x,1,:y,2,:z,3]

So my question is how are the ":x, :y, :z" elements recognized? Are they strings? And under what circumstances is the second method preferred?

Xavier
  • 323
  • 3
  • 10

1 Answers1

1

Your second example doesn't actually work. The correct syntax is:

Hash[:x,1,:y,2,:z,3]

The two examples are also actually different. The first has strings as keys; the second uses symbols.

For more information on what symbols are, see "Ruby Symbols", "The Ruby_Newbie Guide to Symbols", "The Difference Between Ruby Symbols and Strings" or Ruby's documentation on the Symbol class. (For even more information, simply do a Google search for "ruby symbol")

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
tckmn
  • 57,719
  • 27
  • 114
  • 156
  • When creating anchor text, use something more descriptive that helps the reader identify where the link will take them. See "[6.1 Link text](http://www.w3.org/TR/WCAG10-HTML-TECHS/#link-text)" in "HTML Techniques for Web Content Accessibility Guidelines 1.0" for more information. – the Tin Man Dec 17 '14 at 23:17