yaml issues

J

Junkone

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

Stefano Crocco

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
 
J

jonty

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

Therefore there is a problem with your installation
 
S

Stefano Crocco

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
 
K

konstantin.mailinglists

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

Therefore there is a problem with your installation

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

Rick DeNatale

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

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

Stefano Crocco

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
 

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

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top