DATA and require

Hi,

I have a file that uses END and DATA to read in a large
string. It works fine when I run it directly.

But when I require that file in another one it says

“uninitialized constant DATA”

Why?

Regards,

Karsten Magnuaer

···


http://fastmail.fm - I mean, what is it about a decent email service?

coma_killen@fastmail.fm wrote:

Hi,

I have a file that uses END and DATA to read in a large
string. It works fine when I run it directly.

But when I require that file in another one it says

“uninitialized constant DATA”

Why?

I guess DATA is associated with the $0 file, i.e., the file that was
first passed to the ruby interpreter. For example:

$ cat a.rb
require ‘b’
END
In DATA of a.rb

$ cat b.rb
p DATA.gets(nil)
END
In DATA of b.rb

$ ruby a.rb
“In DATA of a.rb\n”

$ ruby b.rb
“In DATA of b.rb\n”