Saving YAML data

  • Thread starter Nigel Wilkinson
  • Start date
N

Nigel Wilkinson

Hi

I've just started playing with YAML but am having problems saveing the
file. What I can work out from the docs is that I should use something
like:-

require 'yaml'
y = YAML.Store.new( "./yaml.store.1", :Indent => 2, :Separator =>
'---.pstore' )

however when I do this in irb I get

irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> y = YAML.Store.new( "./yaml.store.1", :Indent => 2,
:Separator => '---.pstore' )
NoMethodError: undefined method `Store' for YAML:Module
from (irb):2
irb(main):003:0>

Anyone know what I'm doing wrong.

Cheers
Nigel
 
E

ES

Le 6/6/2005 said:
Hi

I've just started playing with YAML but am having problems saveing the
file. What I can work out from the docs is that I should use something
like:-

require 'yaml'
y =3D YAML.Store.new( "./yaml.store.1", :Indent =3D> 2, :Separator =3D>
'---.pstore' )

however when I do this in irb I get

irb(main):001:0> require 'yaml'
=3D> true
irb(main):002:0> y =3D YAML.Store.new( "./yaml.store.1", :Indent =3D> 2,
:Separator =3D> '---.pstore' )
NoMethodError: undefined method `Store' for YAML:Module
from (irb):2
irb(main):003:0>

Anyone know what I'm doing wrong.

This is what I usually use:

File.open('filename', 'w+b') {|file| YAML.dump my_data, file}
Cheers
Nigel

E
 
A

Ara.T.Howard

Hi

I've just started playing with YAML but am having problems saveing the file.
What I can work out from the docs is that I should use something like:-

require 'yaml'
y = YAML.Store.new( "./yaml.store.1", :Indent => 2, :Separator =>
'---.pstore' )

however when I do this in irb I get

irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> y = YAML.Store.new( "./yaml.store.1", :Indent => 2,
:Separator => '---.pstore' )
NoMethodError: undefined method `Store' for YAML:Module
from (irb):2
irb(main):003:0>

Anyone know what I'm doing wrong.

YAML::Store
^^
^^
^^

you are trying to call the 'Store' method of the YAML module with 'YAML.Store'

cheers.

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| My religion is very simple. My religion is kindness.
| --Tenzin Gyatso
===============================================================================
 
E

Eric Hodel

irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> y = YAML.Store.new( "./yaml.store.1", :Indent =>
2, :Separator => '---.pstore' )
NoMethodError: undefined method `Store' for YAML:Module
from (irb):2
irb(main):003:0>

Anyone know what I'm doing wrong.

YAML::Store

signifies calling a method.
 
N

Nigel Wilkinson

This is what I usually use:

File.open('filename', 'w+b') {|file| YAML.dump my_data, file}

E

Thanks, that seems to do what I want.

With ref to the other solution for some reason I still get

irb(main):051:0* require 'yaml'
=> false
irb(main):052:0> y = YAML::Store.new( "./yaml.store.1", :Indent => 2,
:Separator => '---.pstore' )
NameError: uninitialized constant YAML::Store
from (irb):52
irb(main):053:0>

But I have a result that works

Cheers
Nigel
 
M

Mark Hubbart

Hi,

--On Tuesday, June 07, 2005 07:08:17 +0900 ES <[email protected]>
wrote:
=20
=20
Thanks, that seems to do what I want.
=20
With ref to the other solution for some reason I still get
=20
irb(main):051:0* require 'yaml'
=3D> false
irb(main):052:0> y =3D YAML::Store.new( "./yaml.store.1", :Indent =3D> 2,
:Separator =3D> '---.pstore' )
NameError: uninitialized constant YAML::Store
from (irb):52
irb(main):053:0>

Try "require 'yaml/store'", and it should work. The YAML::Store
functionality is defined in a separate place, and isn't required with
just "require 'yaml'".

HTH,
Mark
 
A

Ara.T.Howard

Thanks, that seems to do what I want.

With ref to the other solution for some reason I still get

irb(main):051:0* require 'yaml'
=> false

require 'yaml/store'
irb(main):052:0> y = YAML::Store.new( "./yaml.store.1", :Indent => 2,
:Separator => '---.pstore' )
NameError: uninitialized constant YAML::Store
from (irb):52
irb(main):053:0>

But I have a result that works

Cheers
Nigel

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| My religion is very simple. My religion is kindness.
| --Tenzin Gyatso
===============================================================================
 
N

Nigel Wilkinson

--On Wednesday, June 08, 2005 07:28:14 +0900 Mark Hubbart
Try "require 'yaml/store'", and it should work. The YAML::Store
functionality is defined in a separate place, and isn't required with
just "require 'yaml'".

Yep, works a treat,

Cheers
Nigel
 

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
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top