Objects

can i create objects and store them in a file once and use it other
times when i need it after reopening the program.. please helpp...!!

You sure can. Here's an example:

   object = "whatever"

   # this code saves an object
   File.open("path/to/file", "w") { |file| Marshal.dump(object, file) }

   # this code loads the object back
   object = File.open("path/to/file") { |file| Marshal.load(file) }

Hope that helps.

James Edward Gray II

···

On Mar 21, 2008, at 11:19 AM, HadsS wrote:

can i create objects and store them in a file once and use it other
times when i need it after reopening the program.. please helpp...!!

Just a small addition: I usually prefer to use mode "b" for marshal files because they are binary, it helps documenting and it is more cross platform.

Kind regards

  robert

···

On 21.03.2008 17:29, James Gray wrote:

On Mar 21, 2008, at 11:19 AM, HadsS wrote:

can i create objects and store them in a file once and use it other
times when i need it after reopening the program.. please helpp...!!

You sure can. Here's an example:

   object = "whatever"

   # this code saves an object
   File.open("path/to/file", "w") { |file| Marshal.dump(object, file) }

   # this code loads the object back
   object = File.open("path/to/file") { |file| Marshal.load(file) }

Hope that helps.