YAML Problem YAML::Object

Discussion in 'Ruby' started by Fransiscus Xaverius, Dec 14, 2007.

  1. This was already saved in my database :

    c.lawsuit.customer_service_location

    => "--- !ruby/object:Address \nattributes: \n created_on: 2006-02-24
    12:30:19 \n city: Alex City\n line1: 441 Saint Bernard Drive\n zip:
    \"35086\"\n ''\n id: \"124\"\n contact_detail_id: \"128\"\n detail_key:
    Home Address \n state: AL"

    AND I DO THIS

    >> my_test = YAML.load c.lawsuit.customer_service_location


    =>#<YAML::Object:0xb7986eb8 @class="Address",
    @ivars={"attributes"=>{"line1"=>"441 Saint Bernard Drive", "city"=>"Alex
    City", "created_on"=>"2006-02-24 12:30:19", "line2"=>"", "zip"=>"35086",
    "id"=>"124", "state"=>"AL", "detail_key"=>"Home Address",
    "contact_detail_id"=>"128"}}>

    PROBLEM
    ------------------------
    >> my_test.city

    NoMethodError: Undefined 'city' for #<YAML::Object:0xb7986eb8>
    from (irb): 93
    from : 0


    THE QUESTION
    --------------
    How I can call city's value like doing below :

    call_address = Address.find 128
    => #<Address:0xb79076ac @attributes={"created_on"=>"2006-02-24
    12:30:19", "city"=>"Alex City", "line1"=>"441 Saint Bernard Drive",
    "zip"=>"35086",
    "line2"=>"", "id"=>"124", "contact_detail_id"=>"128",
    "detail_key"=>"Home
    Address", "state"=>"AL"}>

    call_address.city
    => "Alex City"

    Thank You
    FX
    --
    Posted via http://www.ruby-forum.com/.
    Fransiscus Xaverius, Dec 14, 2007
    #1
    1. Advertising

  2. Fransiscus Xaverius

    yermej Guest

    Re: YAML Problem YAML::Object

    On Dec 14, 11:38 am, Fransiscus Xaverius <>
    wrote:
    > This was already saved in my database :
    >
    > c.lawsuit.customer_service_location
    >
    > => "--- !ruby/object:Address \nattributes: \n created_on: 2006-02-24
    > 12:30:19 \n city: Alex City\n line1: 441 Saint Bernard Drive\n zip:
    > \"35086\"\n ''\n id: \"124\"\n contact_detail_id: \"128\"\n detail_key:
    > Home Address \n state: AL"
    >
    > AND I DO THIS
    >
    > >> my_test = YAML.load c.lawsuit.customer_service_location

    >
    > =>#<YAML::Object:0xb7986eb8 @class="Address",
    > @ivars={"attributes"=>{"line1"=>"441 Saint Bernard Drive", "city"=>"Alex
    > City", "created_on"=>"2006-02-24 12:30:19", "line2"=>"", "zip"=>"35086",
    > "id"=>"124", "state"=>"AL", "detail_key"=>"Home Address",
    > "contact_detail_id"=>"128"}}>
    >
    > PROBLEM
    > ------------------------>> my_test.city
    >
    > NoMethodError: Undefined 'city' for #<YAML::Object:0xb7986eb8>
    > from (irb): 93
    > from : 0
    >
    > THE QUESTION
    > --------------
    > How I can call city's value like doing below :
    >
    > call_address = Address.find 128
    > => #<Address:0xb79076ac @attributes={"created_on"=>"2006-02-24
    > 12:30:19", "city"=>"Alex City", "line1"=>"441 Saint Bernard Drive",
    > "zip"=>"35086",
    > "line2"=>"", "id"=>"124", "contact_detail_id"=>"128",
    > "detail_key"=>"Home
    > Address", "state"=>"AL"}>
    >
    > call_address.city
    > => "Alex City"
    >
    > Thank You
    > FX
    > --
    > Posted viahttp://www.ruby-forum.com/.


    It should work so long as the environment where you load the YAML has
    the correct definition of the Address class. In your first example
    (where it isn't working right), you should be able to add something
    before your YAML.load like:

    require 'address'

    where the file address.rb has the class definition of Address. Without
    that, Ruby can't actually instantiate the Address class so you just
    get the YAML::Object object that you're seeing.
    yermej, Dec 14, 2007
    #2
    1. Advertising

  3. Re: YAML Problem YAML::Object

    You just saved my life from fired. Thank You.
    :D
    FX

    yermej wrote:
    > On Dec 14, 11:38 am, Fransiscus Xaverius <>
    > wrote:
    >>
    >>
    >> 12:30:19", "city"=>"Alex City", "line1"=>"441 Saint Bernard Drive",
    >> --
    >> Posted viahttp://www.ruby-forum.com/.

    >
    > It should work so long as the environment where you load the YAML has
    > the correct definition of the Address class. In your first example
    > (where it isn't working right), you should be able to add something
    > before your YAML.load like:
    >
    > require 'address'
    >
    > where the file address.rb has the class definition of Address. Without
    > that, Ruby can't actually instantiate the Address class so you just
    > get the YAML::Object object that you're seeing.


    --
    Posted via http://www.ruby-forum.com/.
    Fransiscus Xaverius, Dec 14, 2007
    #3
    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. RubyQuestions
    Replies:
    0
    Views:
    218
    RubyQuestions
    Dec 3, 2003
  2. Paul Battley

    YAML.dump/YAML.load bug

    Paul Battley, Aug 3, 2005, in forum: Ruby
    Replies:
    0
    Views:
    173
    Paul Battley
    Aug 3, 2005
  3. Eric Promislow
    Replies:
    4
    Views:
    201
    Eric Promislow
    Oct 31, 2006
  4. Joshua Choi

    yaml.rb and YAML "%" directives

    Joshua Choi, Jan 14, 2007, in forum: Ruby
    Replies:
    1
    Views:
    158
  5. Jonathan Gold
    Replies:
    0
    Views:
    131
    Jonathan Gold
    May 19, 2009
Loading...

Share This Page