Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > YAML Problem YAML::Object

Reply
Thread Tools

YAML Problem YAML::Object

 
 
Fransiscus Xaverius
Guest
Posts: n/a
 
      12-14-2007
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/.

 
Reply With Quote
 
 
 
 
yermej
Guest
Posts: n/a
 
      12-14-2007
On Dec 14, 11:38 am, Fransiscus Xaverius <homebeautyp...@yahoo.co.id>
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.
 
Reply With Quote
 
 
 
 
Fransiscus Xaverius
Guest
Posts: n/a
 
      12-14-2007
You just saved my life from fired. Thank You.

FX

yermej wrote:
> On Dec 14, 11:38 am, Fransiscus Xaverius <homebeautyp...@yahoo.co.id>
> 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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Broken YAML.dump with YAML::Object (Missing String#each) Jonathan Gold Ruby 0 05-19-2009 07:53 PM
yaml.rb and YAML "%" directives Joshua Choi Ruby 1 01-14-2007 07:53 AM
Puzzling over why ri can open the std ruby/ri .yaml files, but raw yaml can't Eric Promislow Ruby 4 10-31-2006 10:15 PM
YAML.dump/YAML.load bug Paul Battley Ruby 0 08-03-2005 08:28 PM
YAML Question: Using YAML::YamlNode#transform Method to get float values? RubyQuestions Ruby 0 12-03-2003 02:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57