how to say # in ruby

R

Rick DeNatale

Bear in mind that if the shell started the program and the program
specified on the shebang line wasn't the ruby interpreter, the code
quoted above doesn't run.

Since it is running, somehow the ruby interpreter has been started and
given a file containing text that may or may not actually be Ruby code.
This could happen if you started ruby by explicitly executing the "ruby"
command, or if you're running on Windows where there is no shell to do
shebang interpreting for you.

That bit of code inspects the shebang line and, if the word "ruby"
doesn't appear on the line, it tries to execute what it assumes is a
program.

Actually what that code does is:

If the first line is a shebang
if it doesn't contain 'ruby' somewhere
extract the path which it seems to be wanting to run
produce a fatal error
else
extract any arguments for the ruby command
continue to process.
end
end

So it is trying to avoid accidentially running, say a bash or perl
script using the ruby interpreter.
 
R

Rick DeNatale

Robert Klemme wrote:

Thanks for your continued attention, robert. That link was very
interesting. (Ich hatte google noch nie auf deutsch gesehen.) One
snippet I found there was this one:

288: {
printk( " no PCI bus?@#!\n");
return NumberOfAdapters;

This has #! looking very uncommentlike. Is #! a token separate from # ?
(Does ruby have tokens at all?)

Well the link that Robert posted was to some C code, so it shouldn't
be expected to give much insight into Ruby syntax/lexing.

Note that there ARE cases in Ruby where a # does not start a comment,
for example, it is used tor interpolation in string and regular
expression 'literals'

a = "Foo"
puts "The value of a is #{a}"

"Foo Fighters".match(/#{a)/)

And of course a # inside of string or regexp doesn't start a comment
even if it isn't triggering interpolation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,474
Latest member
AntoniaDea

Latest Threads

Top