Page 1 of 1
Save / Load RubyObject to File
Posted: Tue Oct 01, 2013 9:13 pm
by chackl
Hello!
I did some simple save and load modules for ruby objects.
My Problem was that i got realy big objects and this module kees it easier to save object to a binary file.
WARNING: Binay files are no TEXT Files!!! - Never open and save them with a text Editor!!!
If you want to save a text to the object use an object-Array.
Regards
C.Hackl
Re: Save / Load RubyObject
Posted: Tue Oct 01, 2013 9:33 pm
by billv
Thanks for sharing.....

.
Re: Save / Load RubyObject
Posted: Tue Oct 01, 2013 9:56 pm
by chackl
u'r welcome
Please NOTE:Custom classes Need some extras to get it working:
http://ruby-doc.org/core-2.0.0/Marshal.htmlNot working with Bitmap objects - needs a Workaround. - I'll be on this.
Regards
Re: Save / Load RubyObject
Posted: Tue Oct 01, 2013 11:25 pm
by billv
chackl wrote:Custom classes Need some extras
Yeh i got caught out....trying to make it work...went inside module
and saw 'marshal'....who's that..??...never heard of him...
Had planned to try my first 'class' maybe next week....
In over my head again
chackl wrote:I'll be on this.
thanks...i can watch and learn...

.
Re: Save / Load RubyObject to File
Posted: Wed Oct 02, 2013 8:56 am
by trogluddite
'Marshal' is a special class that used for 'serialising' objects - taking a Ruby object and converting it into a stream of binary numbers, so that the object can be saved and then re-created when loaded.
But it only works for Ruby classes that have special methods defined to say how the conversion should be done. Most of the standard Ruby classes have the 'marshal' methods, but many FS specific classes don't.
Behind the scenes, the FS 'loadState' and 'saveState' methods, and storing the input/output values, will be using 'Marshal' - which is why there are some objects (e.g. bitmaps, graphics paths, brushes) that can't be stored between sessions.
Re: Save / Load RubyObject to File
Posted: Wed Oct 02, 2013 9:13 am
by chackl
i think it will be easy to restore Brushes and so on.... I'm just saving the input variables for Brush class and calculate it again afer load.
For Bitmaps.... difficult. I'm working now with the FloStone primitive get pixel and save it to a 2 dimensional color array within ruby. And this is slow.... Getting back a bitmap is also tricky - Also a Primitive again View to bitmap and i draw every pixel as a recktangle in ruby (But this is much faster)
If you use it you have to get all classes ready for it otherwise there will be loads of lost data.
Regards
Re: Save / Load RubyObject to File
Posted: Tue Nov 05, 2013 12:04 pm
by imi90
Is there someone out there who knows how to 'capture' the 'ZeroDivisionError' in the Flowstone Ruby interpreter and rectify the code below?
Re: Save / Load RubyObject to File
Posted: Tue Nov 05, 2013 1:23 pm
by chackl
imi90 wrote:Is there someone out there who knows how to 'capture' the 'ZeroDivisionError' in the Flowstone Ruby interpreter and rectify the code below?
Could you please open a new topic if it is not belonging to save/load Ruby Objects?
Thanks