How to say # in ruby

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.

···

On 2/11/08, Tim Hunter <rmagick@gmail.com> wrote:

Robert Klemme wrote:

> I'm not sure what you're at here. You posted code from the Ruby
> interpreter but the magical bit of shebang is done by the shell or OS
> not Ruby.

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.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

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.

···

On 2/11/08, Gerry Ford <wade@zaxfuuq.net> wrote:

Robert Klemme wrote:

> I'm not sure what you're at here. You posted code from the Ruby
> interpreter but the magical bit of shebang is done by the shell or OS
> not Ruby. See for example:
>
> http://www.google.com/codesearch?hl=de&q=+lang:c+package:kernel+"%23!"+show:BxIe8bIKbEg:X-2Nm3hrV4s:RaABaUcqtps&sa=N&cd=2&ct=rc&cs_p=http://kernel.org/pub/linux/kernel/v2.4/linux-2.4.34.1.tar.bz2&cs_f=linux-2.4.34.1/fs/binfmt_script.c

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?)

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/