SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Tuesday, April 21, 2009

Printing ruby console output to text file

Ruby console output to text file


Its easy to print the output from the console to a text file or any others.For example


User.all will shows
=> [#<User id: 1, patientid: "110012009", firstname: "Gen", middlename: "warrior", lastname: "None", age: 24, sex: 1, dateofbirth: nil>]

Then open the file
f= File.open('text.txt','w')
f.write User.all.inspect
f.close
I have used inspect method since it returns a string containing a human-readable representation of obj.

No comments :

Post a Comment