[LRUG] Serialising a struct
Stephen Nelson-Smith
sanelson at gmail.com
Mon Apr 14 07:43:46 PDT 2014
Hi,
On Mon, Apr 14, 2014 at 3:27 PM, Paul Battley <pbattley at gmail.com> wrote:
> On 14 April 2014 15:07, Stephen Nelson-Smith <sanelson at gmail.com> wrote:
> > Marshal doesn't support dumping from a Struct
>
> Marshal doesn't support dumping an anonymous class. Structs are fine
> if they are assigned to a constant:
>
> [1] pry(main)> Foo = Struct.new(:bar)
> => Foo
> [2] pry(main)> Marshal.dump(Foo.new)
> => "\x04\bS:\bFoo\x06:\bbar0"
>
> I don't know if that helps you. If the structs are defined by the AWS
> library, perhaps not.
>
Yep - thanks for the clarification. What I get back from AWS is already an
instance of the struct defined by AWS:
[56] pry(main)> i = ec2.describe_images(owners:
['self']).images.first.to_h; nil
=> nil
[57] pry(main)> Marshal.dump(i)
TypeError: can't dump anonymous class #<Class:0x007ff5d9b6d768>
from (pry):55:in `dump'
S.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20140414/00338098/attachment-0003.html>
More information about the Chat
mailing list