From: "Michael T. Richter" Date: 2007-09-07T14:39:01+09:00 Subject: Re: Equivalent of "source" in ruby? --=-WcM5+U4SL0cR+iGFMkvS Content-Type: multipart/alternative; boundary="=-AWc4XdvKKeRBoE7GubRp" --=-AWc4XdvKKeRBoE7GubRp Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Fri, 2007-07-09 at 14:17 +0900, Todd A. Jacobs wrote: > Contrary to my expectations, if I have some variable assignments in an > external file, I can't simply call: >=20 > load rcfile >=20 > to have it sourced. Instead, I found myself having to do this: >=20 > IO.foreach(rcfile) do |line| > eval line > end >=20 > which seems lame. Is there a better way? #test1.rb: @a =3D 5 @b =3D 4 =20 require 'test2' =20 p @a p @b p @c #----8<----- #test2.rb: @b =3D 3 @c =3D 2 $ ruby test1.rb 5 3 2 $ Or am I missing something? --=20 Michael T. Richter (GoogleTalk: ttmrichter@gmail.com) So much of what we call management consists in making it difficult for people to work. (Peter Drucker) --=-AWc4XdvKKeRBoE7GubRp Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Fri, 2007-07-09 at 14:17 +0900, Todd A. Jacobs wrote:
Contrary to my expectations, if I have some variabl=
e assignments in an
external file, I can't simply call:

    load rcfile

to have it sourced. Instead, I found myself having =
to do this:

    IO.foreach(rcfile) do |line|
	eval line
    end

which seems lame. Is there a better way?

#test1.rb:
@a =3D 5
@b =3D 4

require 'test2'

p @a
p @b
p @c
#----8<-----

#test2.rb:
@b =3D 3
@c =3D 2

$ ruby test1.rb
5
3
2
$

Or am I missing something?
--
Michael T. Richter <ttmri= chter@gmail.com> (GoogleTalk: ttmrichter@gmail.com)
So much of what we call management consists in making it difficult for p= eople to work. (Peter Drucker)
--=-AWc4XdvKKeRBoE7GubRp-- --=-WcM5+U4SL0cR+iGFMkvS 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) iD8DBQBG4OPmLqyWkKVQ54QRAonVAJ9VAX9SOQ/2Q6wq5btN/cCSijdgIgCfXVBn D7TCmkerXek1CS9KkDRrCIY= =g3BK -----END PGP SIGNATURE----- --=-WcM5+U4SL0cR+iGFMkvS--