From: Wilbert Berendsen Date: 2003-01-26T23:41:58+09:00 Subject: Re: datafiles as Ruby source musings -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sunday 26 January 2003 13:57, nobu.nokada@softhome.net wrote: > Hi, > > At Sun, 26 Jan 2003 06:18:09 +0900, > > Wilbert Berendsen wrote: > > module Data > > load "datafile" > > end > > Kernel#load code in the file into toplevel context if (omitted) > second argument is false, or an anonymous module. > > If it were return that anonymous module, you can write as: > > module Data > include load("datafile", true) > end > > or even > > Data = load("datafile", true) Wow!! I did not know the load method would return the anonymous module. This is nice! > > 2. > > > > Other files which my app will need, must contain Makefile-like > > structures. I would rather just "load" the file, and having the Ruby > > interpreter take care of the parsing (example:) > > > > ALSA && ( > > depend "audio/alsa-driver" { |p| p.version >= 0.9 } > > configure << "--enable-alsa" > > ) > > > > where 'depend' and 'configure' are just methods in the current instance, > > and 'ALSA' a constant defined in a module that got included. But again > > using 'obj.instance_eval File.new("file").read' is the only thing I can > > think of. > > To do it, Kernel#load would need to accept a Module as second > argument, like as: > > load("depend", Data) > > > Although I don't guess this modification rarely breaks existing > code, but not sure it's a good thing. I think I'll have to stick to eval. Of cource eval is dangerous, but my process runs a an unprivileged user (like 'nobody') and the scripts are trusted. Thanks for your ideas (also the others :-) Wilbert - -- Wilbert Berendsen (http://www.xs4all.nl/~wbsoft/) To understand recursion, one must first understand recursion. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE+M/M3x+vk367Vl7wRAhM4AJ9GhmkqToNlZCFRI9kxw+ai5Tb3ewCg3e9a iQeD7WMTQ2wNf1mV4mKT4G4= =U+xJ -----END PGP SIGNATURE-----