[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

HadsS

3/21/2008 4:20:00 PM

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...!!
2 Answers

James Gray

3/21/2008 4:30:00 PM

0

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.

James Edward Gray II

Robert Klemme

3/22/2008 12:24:00 PM

0

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.

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