0

When I want to debug the following hash, it returns try2test2.

dictionary = {
  "test" => 2,
  "try" => 2
}

puts dictionary
# => try2test2

Are there any other ways to do it so that it will give you the full list like {'test': 2, 'try': 2}?

sawa
  • 165,429
  • 45
  • 277
  • 381
tipsywacky
  • 3,374
  • 5
  • 43
  • 75

3 Answers3

5

As V. Melnychuk mentioned, JSON is a good option, just remember to import the "json" module first:

require "json"
dictionary.to_json

in general, you can retreive a readable string version of an object by calling inspect on it:

dictionary.inspect

finally, there is a "pp" module to pretty-print variable (pretty much like the pprint module in python):

require "pp"
pp dictionary

Hope it helps !

aurelien.n
  • 106
  • 3
2

Try to convert object to JSON

dictionary.to_json
vmeln
  • 1,289
  • 1
  • 16
  • 40
0

You could also do p dictionary which sends inspect by default:

dictionary = {
  "test" => 2,
  "try" => 2
}

p dictionary      # => {"test"=>2, "try"=>2}
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43