The puts method calls to_s in its arguments and prints the result. However, the p method calls to check on its arguments and prints the result:
{1=>"Jane", 2=>"Thomas"}.to_s
{1=>"Jane", 2=>"Thomas"}.inspect
So, to have a beautiful Hash listing, use
puts {1=>"Jane", 2=>"Thomas"}.inspect
or
p {1=>"Jane", 2=>"Thomas"}
source
share