From: "Michael T. Richter" Date: 2007-08-31T20:31:38+09:00 Subject: Weird problem with DATA and __END__ --=-M3ARuu4mBmyahaZUfWG5 Content-Type: multipart/alternative; boundary="=-0yx/9FOCCP88FVbBYwnC" --=-0yx/9FOCCP88FVbBYwnC Content-Type: text/plain Content-Transfer-Encoding: quoted-printable File: test1.rb: require 'test2' puts "test1.rb =3D " + DATA.readlines.to_s __END__ This is the data in test1.rb. File: test2.rb: puts "test2.rb =3D " + DATA.readlines.to_s __END__ This is the data in test2.rb. Command session: $ ruby test1.rb test2.rb =3D This is the data in test1.rb. test1.rb =3D=20 $=20 To say this is unexpected is putting it mildly. What I'd expect to see is: $ ruby test1.rb test2.rb =3D This is the data in test1.rb. test1.rb =3D=20 $=20 So two questions: * Why is test2 getting the data from test1 and not from itself? * How can get the behaviour I'm looking for? --=20 Michael T. Richter (GoogleTalk: ttmrichter@gmail.com) All really first class designers are both artists, engineers, and men of a powerful and intolerant temper, quick to resist the least modification of the plans, energetic in fighting the least infringement upon what they regard as their own sphere of action. (Nevil Shute) --=-0yx/9FOCCP88FVbBYwnC Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable File: test1.rb:
require 'test2'
puts "test1.rb =3D " + DATA.readlines.to_s
__END__
This is the data in test1.rb.

File: test2.rb:
puts "test2.rb =3D " + DATA.readlines.to_s
__END__
This is the data in test2.rb.

Command session:
$ ruby test1.rb
test2.rb =3D This is the data in test1.rb.
test1.rb =3D
$

To say this is unexpected is putting it mildly.  What I'd expect to se= e is:
$ ruby test1.rb
test2.rb =3D This is the data in test1.rb.
test1.rb =3D
$

So two questions:
--
Michael T. Richter <ttmri= chter@gmail.com> (GoogleTalk: ttmrichter@gmail.com)
All really first class designers are both artists, engineers, and men of= a powerful and intolerant temper, quick to resist the least modification o= f the plans, energetic in fighting the least infringement upon what they re= gard as their own sphere of action. (Nevil Shute)
--=-0yx/9FOCCP88FVbBYwnC-- --=-M3ARuu4mBmyahaZUfWG5 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (GNU/Linux) iD8DBQBG1/wOLqyWkKVQ54QRAqgNAKCDZTU8EFM4FN0I/JS0sDsm3K7kmwCfV6Sk zzFKWlB/XRx3pL9qKFW6hlI= =SgIE -----END PGP SIGNATURE----- --=-M3ARuu4mBmyahaZUfWG5--