Robert Klemme
3/22/2008 12:24:00 PM
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