Reputation: 37
After saving some values into the database, I am finding it difficult to print them out. Though I have been able to pull the data out of the database, the output is like the following:
@vars={:object=>"46789620999001", :source_id=>1, :comment=>"["This is
my first commenttoday and tommorrow", "This is my first commenttoday
and tommorrow", "This is my first commenttoday and tommorrow", "This
is my first commenttoday and tommorrow", "This is my first comment",
"This is my first comment", "its nice!!!", "Many people do not take
this serious. In this life we have a big role to play in making
ourselves what we would be. It is only God that can help us to live
that life which we have planned, so we can only pray to Him who is the
all and all in our life to help
us."]", :title=>"", :content=>"<div>Life is beautiful. In this life,
whatever you see is what you will use to make out your way. People
around you can help you in many things and ways but can never live
your life for you. It is left for you to live your life, make and take
decisions that you think will help you in living out your dream life.
I believe everybody has a dream life he would like to live. Whatever
decisions one take today will go a long way in determining the kind of
life the one will live in future.<br />Take this as an advise.Bye </
div><div class="blogger-post-footer"><img width='1' height='1'
src='https://blogger.googleusercontent.com/tracker/
6876835757625487750-2447909010390406819?l=godwinagada.blogspot.com'
alt='' /></div>", :author=>"["Godwin",
"ken"]", :category=>"Reality", :post_id=>"", :date=>"2010-06-04", :FileName=>"first"}
>]
please can someone help out in referring to each of the data in this output eg.
@output.each { |g|
puts g.FileName
puts g.post_id
}
etc
Upvotes: 0
Views: 1547
Reputation: 31726
Try pp, from the standard library.
require 'pp'
pp @vars
There is another alternative called awesome_print, you can dl the gem from http://rubygems.org/gems/awesome_print that would look like this
require 'rubygems'
require 'ap'
ap @vars
Either of these should print the hash in a format that is easier to read.
Upvotes: 0
Reputation: 16
You have a hash, which contains a set of keys with each key pointing to a value. There are several ways you can deal with them:
@vars.each do |key, value| puts "#{key} => #{value} end
Upvotes: 0