# YAML Problem YAML::Object

**URL:** <https://www.ruby-forum.com/t/yaml-problem-yaml-object/123182>\
**Category:** Ruby\
**Created:** [December 14, 2007, 6:38pm UTC](https://www.ruby-forum.com/t/yaml-problem-yaml-object/123182 "2007-12-14T18:38:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![malioboro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@malioboro](https://www.ruby-forum.com/u/malioboro)\
**Post date:** [December 14, 2007, 6:38pm UTC](https://www.ruby-forum.com/t/yaml-problem-yaml-object/123182/1 "2007-12-14T18:38:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![malioboro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@malioboro](https://www.ruby-forum.com/u/malioboro)\
**Post date:** [December 14, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/yaml-problem-yaml-object/123182/2 "2007-12-14T22:01:49Z")

</div>

On Dec 14, 11:38 am, Fransiscus X. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

---

<div class="post-metadata">

**Author:** ![malioboro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/eb8c5e/32.png) [@malioboro](https://www.ruby-forum.com/u/malioboro)\
**Post date:** [December 14, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/yaml-problem-yaml-object/123182/3 "2007-12-14T22:17:10Z")

</div>

You just saved my life from fired. Thank You.  
😃  
FX

yermej wrote:

> On Dec 14, 11:38 am, Fransiscus X. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> 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.
