Jodi Showers
2006-Jul-21 23:36 UTC
[Rails] [RESOLVED] Marshal.dump not dumping entire object?
After sending this I realized that this was a Ruby not Rails issue - but the answer may be interesting for those who choose Marshal over Serialize. So, to close this off I don''t know why marshal.dump wasn''t ''dumping'' all attributes, but adding custom marshaling to PDate did the trick. ala, + def marshal_dump + dumped_obj = [date_precision, ajd, sg, of] + dumped_obj + end + + def marshal_load(dumped_obj) + @date_precision, @ajd, @sg, @of = dumped_obj + end For those that use Runt, I''ve submitted a patch. cheers, Jodi ----------- Greetings, I first want to say that this problem is happening with the Runt gem. This may is likely an implementation issue between Marshal and Runt. While I''ve simultaneously filed this problem with Matt Lipper, I''m also hoping someone here can can guide me a little - either in implementation (usage of Marshal), or to aid me to fix Runt to support Marshal. script/console Loading development environment. >> start_time = Runt::PDate.min(Runt::REDay::ANY_DATE.year, Runt::REDay::ANY_DATE.month,Runt::REDay::ANY_DATE.day, 8, 11) => #<Runt::PDate: 3531621371/1440,0,2299161> >> data = Marshal.dump(start_time) => "\004\010u:\020Runt::PDateA\004\010[\010o:\rRational\a: \017@numeratorl+\a\373C\200\322:\021@denominatori\002\240\005i\000i \003\031\025#" >> obj = Marshal.load(data) => #<Runt::PDate: 3531621371/1440,0,2299161> >> start_time.date_precision => #<Runt::DPrecision::Precision:0x2753cfc @precision=4> >> start_time.date_precision.precision => 4 >> obj.date_precision => nil as you can see - after round tripping through Marshal, date_precision isn''t restored (likely not marshalled) to obj. Is is possible that Runt''s date_precision violates a rule for Marshal.dump? I can note from the source the following, #Pseudo Singletons: YEAR = Precision.year MONTH = Precision.month DAY = Precision.day I seem to remember something about singletons and YAML. Does the same hold for Marshal? Perhaps it''s a deep copy issue? specifying Marshal.dump(start_time, 10) (10 is very deep) makes no diff. Thanx for any thoughts or references that can take me to the next level. cheers, Jodi