[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

yaml issues

Junkone

6/9/2008 7:23:00 PM

i thought yaml was built into Ruby 1.8.6. i seem to be getting
exceptions in creating a store.
irb(main):021:0> require 'yaml'
=> false
irb(main):022:0> y=YAML::Store.new("c:\\temp\\yaml.store.1")
NameError: uninitialized constant YAML::Store
from (irb):22
irb(main):023:0>

6 Answers

Stefano Crocco

6/9/2008 8:12:00 PM

0

On Monday 09 June 2008, Junkone wrote:
> i thought yaml was built into Ruby 1.8.6. i seem to be getting
> exceptions in creating a store.
> irb(main):021:0> require 'yaml'
> => false
> irb(main):022:0> y=YAML::Store.new("c:\\temp\\yaml.store.1")
> NameError: uninitialized constant YAML::Store
> from (irb):22
> irb(main):023:0>

You need to add

require 'yaml/store'

Stefano


jonty

6/10/2008 7:04:00 AM

0

If you require a file in IRB it will output 'true' if it is there

Therefore there is a problem with your installation

Junkone wrote:
> i thought yaml was built into Ruby 1.8.6. i seem to be getting
> exceptions in creating a store.
> irb(main):021:0> require 'yaml'
> => false
> irb(main):022:0> y=YAML::Store.new("c:\\temp\\yaml.store.1")
> NameError: uninitialized constant YAML::Store
> from (irb):22
> irb(main):023:0>
>
>
>
>

Stefano Crocco

6/10/2008 7:56:00 AM

0

On Tuesday 10 June 2008, jonty wrote:
> If you require a file in IRB it will output 'true' if it is there
>
> Therefore there is a problem with your installation

Not exactly. The line

require 'something'

returns true only if the file something.rb (or something.so or something.dll
if it is a C extension) has been loaded. If that file has already been loaded,
it won't be loaded again and require will return false. For example:

irb(main):001:0> require 'yaml'
=> true
irb(main):002:0> require 'yaml'
=> false

The first time, yaml.rb is indeed loaded, and require returns true. The second
time, instead, require notices yaml.rb is already there (in particular, it
looks in the $" global variable), doesn't reload it and returns false.

Stefano



konstantin.mailinglists

6/10/2008 8:01:00 AM

0

On 10 Jun., 09:04, jonty <jontyj...@btinternet.com> wrote:
> If you require a file in IRB it will output 'true' if it is there
>
> Therefore there is a problem with your installation
>
> Junkone wrote:
> > i thought yaml was built into Ruby 1.8.6. i seem to be getting
> > exceptions in creating a store.
> > irb(main):021:0> require 'yaml'
> > => false
> > irb(main):022:0> y=YAML::Store.new("c:\\temp\\yaml.store.1")
> > NameError: uninitialized constant YAML::Store
> >         from (irb):22
> > irb(main):023:0>
>
>

Everything is alright with his installation. When require returns
false, the script has already been loaded.

Rick DeNatale

6/10/2008 12:09:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

On Tue, Jun 10, 2008 at 3:55 AM, Stefano Crocco <stefano.crocco@alice.it>
wrote:

> On Tuesday 10 June 2008, jonty wrote:
> > If you require a file in IRB it will output 'true' if it is there
> >
> > Therefore there is a problem with your installation
>
> Not exactly. The line
>
> require 'something'
>
> returns true only if the file something.rb (or something.so or
> something.dll
> if it is a C extension) has been loaded.


Actually, it returns true if this invocation of require caused the file to
be loaded. The phrase "has been loaded" could be interpreted to mean "has
been loaded during or prior to this call" which is not the right sense.

> If that file has already been loaded,
> it won't be loaded again and require will return false. For example:
>
> irb(main):001:0> require 'yaml'
> => true
> irb(main):002:0> require 'yaml'
> => false
>
> The first time, yaml.rb is indeed loaded, and require returns true. The
> second
> time, instead, require notices yaml.rb is already there (in particular, it
> looks in the $" global variable), doesn't reload it and returns false.


And, to the original issue, if the file can't be found, require won't return
anything, it will raise a LoadError exception.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

Stefano Crocco

6/10/2008 12:12:00 PM

0

On Tuesday 10 June 2008, Rick DeNatale wrote:
> Actually, it returns true if this invocation of require caused the file to
> be loaded. =A0The phrase "has been loaded" could be interpreted to mean "=
has
> been loaded during or prior to this call" which is not the right sense.

Right.

Stefano