YAML dump, load: class not properly reconstituted

Discussion in 'Ruby' started by Pito Salas, Nov 13, 2009.

  1. Pito Salas

    Pito Salas Guest

    Here's some yaml:

    ---
    - :status: :failure
    :filename: !ruby/object:pathname
    path: /mydev/ballots/432Leon200dpibw001.tif
    - :status: :failure
    :skew_angle: -0.72217746154481
    :rotated: -0.72217746154481
    :filename: !ruby/object:pathname
    path: /mydev/ballots/432Leon200dpibw002.tif

    When I load this back into Ruby, I get something like this from pp:

    #<PBScorer:0x1010d9bc8

    {:filename=>
    #<Pathname:0x1010d5370
    @class="Pathname",
    @ivars=
    {"path"=>"/mydev/iaharness/ballotsamples/432Leon200dpibw003.tif"}>}
    ...

    In the debugger, the class of :filename seems to be YAML::something

    So, it looks like the re-encoding of Pathname by Yaml got a bit
    flumoxed. I've tried a bunch of small examples and can't seem to get it
    to reproduce.

    Anyone spot whats wrong before I go deeper and deeper and depper?

    Thanks,

    Pito
    --
    Posted via http://www.ruby-forum.com/.
    Pito Salas, Nov 13, 2009
    #1
    1. Advertising

  2. Pito Salas

    Ryan Davis Guest

    On Nov 13, 2009, at 12:58 , Pito Salas wrote:

    > Here's some yaml:
    >=20
    > ---
    > - :status: :failure
    > :filename: !ruby/object:pathname
    > path: /mydev/ballots/432Leon200dpibw001.tif
    > - :status: :failure
    > :skew_angle: -0.72217746154481
    > :rotated: -0.72217746154481
    > :filename: !ruby/object:pathname
    > path: /mydev/ballots/432Leon200dpibw002.tif
    >=20
    > When I load this back into Ruby, I get something like this from pp:
    >=20
    > #<PBScorer:0x1010d9bc8
    >=20
    > {:filename=3D>
    > #<Pathname:0x1010d5370
    > @class=3D"Pathname",
    > @ivars=3D
    > =

    {"path"=3D>"/mydev/iaharness/ballotsamples/432Leon200dpibw003.tif"}>}

    I suspect you're not telling us all the relevant details. The following =
    code works fine:

    > #!/usr/bin/ruby -w
    >=20
    > require 'yaml'
    > require 'pathname'
    >=20
    > # I had to fix your YAML indentation
    > yaml =3D "---
    > - :status: :failure
    > :filename: !ruby/object:pathname
    > path: /mydev/ballots/432Leon200dpibw001.tif
    > - :status: :failure
    > :skew_angle: -0.72217746154481
    > :rotated: -0.72217746154481
    > :filename: !ruby/object:pathname
    > path: /mydev/ballots/432Leon200dpibw002.tif
    > "
    >=20
    > array =3D YAML.load(StringIO.new(yaml))
    >=20
    > p array.first[:filename].absolute? # =3D> true


    If you comment out the pathname require, then it is a YAML object but it =
    is obvious about it:

    > #<YAML::Object:0x1004abb80 @class=3D"Pathname", =

    @ivars=3D{"path"=3D>"/mydev/ballots/432Leon200dpibw001.tif"}>
    Ryan Davis, Nov 13, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. halfdog
    Replies:
    12
    Views:
    12,432
  2. Replies:
    0
    Views:
    506
  3. Trans
    Replies:
    2
    Views:
    300
    Trans
    Jan 29, 2005
  4. Paul Battley

    YAML.dump/YAML.load bug

    Paul Battley, Aug 3, 2005, in forum: Ruby
    Replies:
    0
    Views:
    176
    Paul Battley
    Aug 3, 2005
  5. Jonathan Gold
    Replies:
    0
    Views:
    136
    Jonathan Gold
    May 19, 2009
Loading...

Share This Page