Forum: Ruby Can't read Yaml for domain type

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Karan R. (Guest)
on 2009-04-27 11:34
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 ?
Joel VanderWerf (Guest)
on 2009-04-27 21:06
(Received via mailing list)
Ganesh Girase wrote:
> 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
This topic is locked and can not be replied to.