Can't read Yaml for domain type

G

Ganesh Girase

I have one yaml file "content.yml" which has content,

---
key: !DBClass
debug: Y
Directory : /var/tmp
name: John
phone: 487394


As, I am trying to load the file via,

obj= YAML.load(File.open("content.yml"))

But i dont know that how to acess the individual variable from this
content.
for eg, How do i will get the Directory or name or phone ?
 
J

Joel VanderWerf

Ganesh said:
I have one yaml file "content.yml" which has content,

---
key: !DBClass
debug: Y
Directory : /var/tmp
name: John
phone: 487394


As, I am trying to load the file via,

obj= YAML.load(File.open("content.yml"))

But i dont know that how to acess the individual variable from this
content.
for eg, How do i will get the Directory or name or phone ?

There should be some code that defines the DBClass type for YAML (maybe
you can check with whoever wrote that data?). In the meantime, you can
do this:

require 'yaml'

h = YAML.load(DATA)["key"].instance_variable_get:)@value)

p h # {"name"=>"John", "Directory"=>"/var/tmp", "phone"=>487394,
"debug"=>"Y"}

p h["Directory"] # "/var/tmp"

__END__

---
key: !DBClass
debug: Y
Directory : /var/tmp
name: John
phone: 487394
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top