I notice how Rails makes heavy use of YAML serialization, but a lot of the Ruby literature I come across places emphasis on Marshal. One powerful technique with marshal is the marshal_dump and marshal_load hooks used to customize storing and retrieving object states. For example, let''s say I have an object that can store as instance variables an arbitrary array of integers. And let''s say I simply want to marshal that array rather than the whole object state, and then later retrieve that data and store it into an allocated but unitialized new instance of the object. Then the marshal_dump and marshal_load hooks come in handy: class Point def initialize(*coords) @coords = coords end def marshal_dump @coords.pack("w*") end def marshal_load(s) @coords = s.unpack("w*") end end Is there a more effective way to achieve something like this in YAML that the Rails community prefers? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/GZdvmxERMyYJ. For more options, visit https://groups.google.com/groups/opt_out.
On Tue, Oct 9, 2012 at 10:48 PM, John Merlino <stoicism1-YDxpq3io04c@public.gmane.org> wrote:> I notice how Rails makes heavy use of YAML serialization, but a lot of the > Ruby literature I come across places emphasis on Marshal.Different tools for different purposes. YAML makes it easy for a *human* looking at something, to tell what''s what, and modify it in a way that probably won''t screw everything up. Marshalled data is generally not intended for human viewing, let alone editing, only for efficient reloading. -Dave -- Dave Aronson, T. Rex of Codosaurus, LLC... aka Available Secret-Cleared Ruby/Rails Freelancer (NoVa/DC/Remote); see http://www.Codosaur.us/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.