Reputation: 34013
Sometimes I choose to print out params
or an object in a view, but when loaded with data it cannot be hard to visually scan.
Is their any "trick" to easily print a hash such that each key-value pair is printed on a new line?
In the console I use y my_hash
.
Upvotes: 2
Views: 6988
Reputation: 56719
Here's a very simple alternative:
<% hash.each do |k,v| %>
<%= k %>: <%= y %> <br />
<% end %>
Upvotes: 2
Reputation: 7744
No trick. There isn't any out-of-the-box way to do this. You'll have to format the hash.
An example:
puts( your_hash.map{ |k,v| "#{k} => #{v}" }.sort )
Upvotes: 4