Self-loading scripts (at Ruby's startup time)

Do they exist? I’m afraid they don’t, or at least I couldnt’ find any
hint in “Programming Ruby” and in ruby-talk. Hope I’m wrong…

Thanks, Andrea

Hi,

Do they exist? I’m afraid they don’t, or at least I couldnt’ find any
hint in “Programming Ruby” and in ruby-talk. Hope I’m wrong…

None.

You can set -r option in RUBYOPT environment variable,

$ ruby -e0

$ cat foo.rb
puts “`#$0’ starts”

$ RUBYOPT=-rfoo ruby -e0
`-e’ starts in /tmp

···

At Thu, 19 Sep 2002 07:17:56 +0900, Overnight wrote:


Nobu Nakada

In article 200209190402.g8J42Ov16830@sharui.nakada.kanuma.tochigi.jp,
nobu.nokada@softhome.net says…

Do they exist? I’m afraid they don’t, or at least I couldnt’ find any
hint in “Programming Ruby” and in ruby-talk. Hope I’m wrong…
None.
You can set -r option in RUBYOPT environment variable,

Thanks. Wouldn’t it be useful to have some special-name, autoloading
script? It would be the necessary starting point in defining a standard
for what happens at Ruby’s startup time.

Andrea

Overnight wrote:

In article 200209190402.g8J42Ov16830@sharui.nakada.kanuma.tochigi.jp,
nobu.nokada@softhome.net says…

Do they exist? I’m afraid they don’t, or at least I couldnt’ find any
hint in “Programming Ruby” and in ruby-talk. Hope I’m wrong…

None.
You can set -r option in RUBYOPT environment variable,

Thanks. Wouldn’t it be useful to have some special-name, autoloading
script? It would be the necessary starting point in defining a standard
for what happens at Ruby’s startup time.

What would the standard be for how installed ruby libraries insert code
into this file? Why not just use BEGIN {} in the library code?

Hi,

···

In message “Re: self-loading scripts (at Ruby’s startup time)” on 02/09/20, Overnight <NOSPAM_jazz_x@libero.it_NOSPAM> writes:

You can set -r option in RUBYOPT environment variable,

Thanks. Wouldn’t it be useful to have some special-name, autoloading
script? It would be the necessary starting point in defining a standard
for what happens at Ruby’s startup time.

I think this should be an application issue. Since Ruby is a general
purpose language, autoloading startup script that is loaded all the
time is not as useful as it seems.
matz.

Thanks. Wouldn’t it be useful to have some special-name, autoloading
script? It would be the necessary starting point in defining a standard
for what happens at Ruby’s startup time.
What would the standard be for how installed ruby libraries insert code
into this file? Why not just use BEGIN {} in the library code?

Hi.

BEGIN {} in library code would init the library for sure, but how would
the library be automatically loaded?

Pythonistas in this newsgroup surely know about site.py, the special file
that Pythons looks for and loads at startup. At current time (and in the
ActiveState distro) it is used to standardize the addition of site-
specific dirs to Python’s search path and the execution of a special
“sitecustomize” module. This is something more elaborate that adding -
r to RUBYOPT.

I was thinking of something similar when I posted my original message.
IMHO, “autorun.rb” would be a nice name :slight_smile: If autorun.rb existed, some
standards could be built upon it. For examples, it could look into a text
file (“autolibs” ???) with a list of libs to require at startup, or it
could look for the equivalent of “sitecustomize” in Python, and load it.
If all this became an accepted standard, a library wishing to make itself
autorun at startup could simply add itself to “autolibs”. Details of each
lib’s initialization, as you point out, could then be encapsulated in
BEGIN {} blocks within the library.

Another rationale for preferring autorun.rb to RUBYOPT, ehm, “hacking” :-
) is that autorun.rb could be included in a distro more easily than code
setting up RUBYOPT. And it looks to me that it would be easier to
maintain.

Well, hope I’ve been clear enough, sorry if my English is not so good :slight_smile:

Bye, Andrea

Thanks. Wouldn’t it be useful to have some special-name, autoloading
script? It would be the necessary starting point in defining a standard
for what happens at Ruby’s startup time.
I think this should be an application issue. Since Ruby is a general
purpose language, autoloading startup script that is loaded all the
time is not as useful as it seems.

mmm… after reading your message, I decided to definitely put aside my
autoload desires and a

set RUBYOPT=-re:/wip/ruby/autorun.rb

appeared in my AUTOEXEC.BAT :slight_smile: Ok, I can live with it, especially since
I realized that I was solving an autoload issue using another autoload
mechanism :slight_smile:

The first draft of autorun.rb is probably a collection of Ruby horrors
(some of them wanted, since I was doing some experiments with scope rules
while I was at it) however here it goes:

module AutoRun

class CFile 
	def CFile.each(filename,&block)
	#read a file line by line, skipping
	#blank lines and comments
	#no reason to define a class, 'twas just
	#an experiment
		if FileTest.exist?(filename)
			f=open(filename,'r')
			f.each {|l|
				l1=l.chomp.sub(/#.*/,'').strip
				yield(l1) if l1.size>0
			}
			f.close
		end
	end
end

@@dir,@@fname=File.split(FILE)

def AutoRun.putex(e,msg)
puts “#{@@fname}: #{msg}:\n #{e.class}: #{e.message}”
end

autopathname=File.join(@@dir,‘autopath’)
CFile.each(autopathname) { |l|
if FileTest.directory?(l)
# puts “Adding #{l}”
$:.unshift(l)
else
puts “#{@@fname}: #{l} is not a valid dir (in
#{autopathname})”
end
}

autolibname=File.join(@@dir,‘autolib’)
puts autolibname
CFile.each(autolibname) { |l|
begin
require l
rescue Exception => e
putex e,“error loading #{l} (in #{autolibname})”
end
}

$:.each {|p|
sitecustomizename=File.join(p,‘sitecustomize.rb’)
if FileTest.exist?(sitecustomizename)
begin
require sitecustomizename
rescue Exception => e
putex e,“error loading #{sitecustomizename}”
else
break
end
end
}

end

I feel like there is something strange/wrong in using @@dir and @@fname
to make them visible in AutoRun.putex(), but it works and… it is a
different issue, anyway. Think I’ll go back and study a little more :slight_smile:

Bye, Andrea

In article MPG.17f4563457f8536d98969d@news.flashnet.it,

···

Overnight <NOSPAM_jazz_x@libero.it_NOSPAM> wrote:

Thanks. Wouldn’t it be useful to have some special-name, autoloading
script? It would be the necessary starting point in defining a standard
for what happens at Ruby’s startup time.
What would the standard be for how installed ruby libraries insert code
into this file? Why not just use BEGIN {} in the library code?

Hi.

BEGIN {} in library code would init the library for sure, but how would
the library be automatically loaded?

Pythonistas in this newsgroup surely know about site.py, the special file
that Pythons looks for and loads at startup. At current time (and in the
ActiveState distro) it is used to standardize the addition of site-
specific dirs to Python’s search path and the execution of a special
“sitecustomize” module. This is something more elaborate that adding -
r to RUBYOPT.

    • GACK! Yet another reason why “Python is not for me”. This is an
      awful idea from my point of view.
    • Booker C. Bense