[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Saving YAML data

Nigel Wilkinson

6/6/2005 9:33:00 PM

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


7 Answers

ES

6/6/2005 10:08:00 PM

0


Le 6/6/2005, "Nigel Wilkinson" <nigel@waspz.co.uk> a écrit:
>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.

This is what I usually use:

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

>Cheers
>Nigel

E

--
template<typename duck>
void quack(duck& d) { d.quack(); }


Ara.T.Howard

6/6/2005 10:13:00 PM

0

Eric Hodel

6/6/2005 10:14:00 PM

0

On 06 Jun 2005, at 14:33, Nigel Wilkinson wrote:

> 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.

--
Eric Hodel - drbrain@segment7.net - http://se...
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04



Nigel Wilkinson

6/7/2005 10:16:00 PM

0

--On Tuesday, June 07, 2005 07:08:17 +0900 ES <ruby-ml@magical-cat.org>
wrote:

> 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




Mark Hubbart

6/7/2005 10:28:00 PM

0

Hi,

On 6/7/05, Nigel Wilkinson <nigel@waspz.co.uk> wrote:
> --On Tuesday, June 07, 2005 07:08:17 +0900 ES <ruby-ml@magical-cat.org>
> wrote:
>
> > 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>

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


Ara.T.Howard

6/7/2005 11:25:00 PM

0

Nigel Wilkinson

6/7/2005 11:46:00 PM

0

--On Wednesday, June 08, 2005 07:28:14 +0900 Mark Hubbart
<discordantus@gmail.com> wrote:
> 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