I wrote this simple program in Ruby
h = {}
h["a"] = "1"
h[:a] = "2"
puts h
h.each { |k, v| puts "#{k} => #{v}" }
Which outputs
{"a"=>"1", :a=>"2"}
a => 1
a => 2
I have a few questions about this code which involve : and " as indexers not by themselves
- When would I use one over the other? I originally found out there was a difference when certain mongo/rails functions I was calling were depended on the
:indexer, while when I parsed json only"indexers were present. - Are there other ways to index a value with a key?
- Is there a way for my
eachto recognize the difference between:and"indexers? It seems thatputswas able to determine buteachwas not