[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to say # in ruby

Gerry Ford

2/4/2008 11:49:00 PM

I'm accustomed to usenet as opposed to whatever this is.

I have a variety of questions about ruby that range in subtlety. It's
odd to think about a syntax that has, e.g., no standard. I wonder if
this place has a moderator or regulars.

My first question is a simple one: how does a person say # in ruby?
I've always called it a hash, which could be ambiguous. I've also heard
it called a pound.

TIA.
--
--
Posted via http://www.ruby-....

21 Answers

Tim Hunter

2/5/2008 12:03:00 AM

0

Dan Ford wrote:
> I'm accustomed to usenet as opposed to whatever this is.
>
> I have a variety of questions about ruby that range in subtlety. It's
> odd to think about a syntax that has, e.g., no standard. I wonder if
> this place has a moderator or regulars.
>
> My first question is a simple one: how does a person say # in ruby?
> I've always called it a hash, which could be ambiguous. I've also heard
> it called a pound.
>
> TIA.
> --

Welcome to Ruby!

"This" is a mailing list called ruby-talk. It's gated to the
comp.lang.ruby newsgroup if you're more comfortable with USENET. There
are no moderators. There are many regulars.

Ruby does not impose a pronunciation on the # symbol. Say it however you
like. We can usually differentiate between the # symbol and the Hash
class by context.

--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

Tim Pease

2/5/2008 12:05:00 AM

0

On Feb 4, 2008, at 4:48 PM, Dan Ford wrote:

> I'm accustomed to usenet as opposed to whatever this is.
>
> I have a variety of questions about ruby that range in subtlety. It's
> odd to think about a syntax that has, e.g., no standard. I wonder if
> this place has a moderator or regulars.
>
> My first question is a simple one: how does a person say # in ruby?
> I've always called it a hash, which could be ambiguous. I've also
> heard
> it called a pound.

octothorpe

<http://www.worldwidewords.org/weirdwords/ww-oc...

But you can call it "hash" or "pound". Everyone will know what you
mean.

Blessings,
TwP

Gerry Ford

2/5/2008 1:20:00 AM

0

Tim Hunter wrote:
> Dan Ford wrote:
>> TIA.
>> --
>
> Welcome to Ruby!
>
> "This" is a mailing list called ruby-talk. It's gated to the
> comp.lang.ruby newsgroup if you're more comfortable with USENET. There
> are no moderators. There are many regulars.

Well, you sound friendly enough. I looked with my news client at
comp.lang.ruby, and these messages are, to my surprise, there for the
perusal. I've updated this site to match my usenet pseudonym. I wanted
to make # the original subject, but the forum software demanded that I
embellish.

#!/usr/bin/env ruby

require 'rubygems'
require 'fruit_processor'

#if __FILE__ == $0
processor = FruitProcessor.new
ARGV[0] == nil ? dir = "." : dir = ARGV[0]
processor.pre_process dir
#end

My second question is about the shebang line: #!
I was surprised to find that it matters what's written here when using
the windows platform. There is no env folder in the bin folder, so if
that's a path, then it's a path to nowhere. What "should" the first
line say?
--
Posted via http://www.ruby-....

Robert Klemme

2/5/2008 4:42:00 PM

0

2008/2/5, Gerry Ford <wade@zaxfuuq.net>:
> Tim Hunter wrote:
> > Dan Ford wrote:
> >> TIA.
> >> --
> >
> > Welcome to Ruby!
> >
> > "This" is a mailing list called ruby-talk. It's gated to the
> > comp.lang.ruby newsgroup if you're more comfortable with USENET. There
> > are no moderators. There are many regulars.
>
> Well, you sound friendly enough. I looked with my news client at
> comp.lang.ruby, and these messages are, to my surprise, there for the
> perusal. I've updated this site to match my usenet pseudonym.

Welcome!

> I wanted
> to make # the original subject, but the forum software demanded that I
> embellish.
>
> #!/usr/bin/env ruby
>
> require 'rubygems'
> require 'fruit_processor'
>
> #if __FILE__ == $0
> processor = FruitProcessor.new
> ARGV[0] == nil ? dir = "." : dir = ARGV[0]

You could as well do

dir = ARGV.shift || "."

> processor.pre_process dir
> #end
>
> My second question is about the shebang line: #!
> I was surprised to find that it matters what's written here when using
> the windows platform. There is no env folder in the bin folder, so if
> that's a path, then it's a path to nowhere. What "should" the first
> line say?

I personally use Ruby on cygwin and most of the time my shebang line
looks like this:

#!/bin/env ruby

No idea about the Windows Ruby version - I haven't used that in ages.

Kind regards

robert


--
use.inject do |as, often| as.you_can - without end

Ben Bleything

2/5/2008 5:28:00 PM

0

On Tue, Feb 05, 2008, Gerry Ford wrote:
> #!/usr/bin/env ruby
>
> require 'rubygems'
> require 'fruit_processor'
>
> #if __FILE__ == $0
> processor = FruitProcessor.new
> ARGV[0] == nil ? dir = "." : dir = ARGV[0]
> processor.pre_process dir
> #end

Ah, okay. You're looking for C-style precompiler directives, yeah? No
such thing in Ruby. To do what you want, just take off the hashes.
Stylistically, indent the body of the loop as well.

Ruby's an interpreted language with no compilation step, so everything
is interpreted top to bottom. There's no harm in putting conditionals
like this in the main body, because if the condition fails it'll just
skip over the body of the conditional.

> My second question is about the shebang line: #!
> I was surprised to find that it matters what's written here when using
> the windows platform. There is no env folder in the bin folder, so if
> that's a path, then it's a path to nowhere. What "should" the first
> line say?

Can't help you there, unfortunately. I only keep a Windows machine for
gaming :)

Ben

Chris Hulan

2/5/2008 5:52:00 PM

0

On Feb 4, 8:20 pm, Gerry Ford <w...@zaxfuuq.net> wrote:
> My second question is about the shebang line: #!
> I was surprised to find that it matters what's written here when using
> the windows platform. There is no env folder in the bin folder, so if
> that's a path, then it's a path to nowhere. What "should" the first
> line say?
> --

I don't think it does matter on windows.
To execute a ruby file (say by double-clicking) you need to have the
file associations
configured.

On *nix the shebang allows a similar function.
#!/usr/bin/env is not a path, it is the 'env' command in /usr/bin
#!/usr/bin/env ruby will find ruby on the PATH then execute it, saves
hard-coding the ruby path (but assumes env is in a standard location).

Cheers

Gerry Ford

2/5/2008 10:23:00 PM

0

Chris Hulan wrote:
> On Feb 4, 8:20 pm, Gerry Ford <w...@zaxfuuq.net> wrote:
>> My second question is about the shebang line: #!
>> I was surprised to find that it matters what's written here when using
>> the windows platform. There is no env folder in the bin folder, so if
>> that's a path, then it's a path to nowhere. What "should" the first
>> line say?
>> --
>
> I don't think it does matter on windows.
> To execute a ruby file (say by double-clicking) you need to have the
> file associations
> configured.
>
> On *nix the shebang allows a similar function.
> #!/usr/bin/env is not a path, it is the 'env' command in /usr/bin
> #!/usr/bin/env ruby will find ruby on the PATH then execute it, saves
> hard-coding the ruby path (but assumes env is in a standard location).

Thanks all for responses.

I do not have an 'env' command in /bin/, which is to say, when I type
env into the dos prompt at ruby/bin/, I get "no such command" from dos.
Maybe I'm in the wrong bin?

This question appears to go to environmental variables. In the
documentation, it suggests to type ruby -e 'puts $:' to see this
information. As output, I get:
C:/ruby/lib/ruby/site_ruby/1.8
C:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt
C:/ruby/lib/ruby/site_ruby
C:/ruby/lib/ruby/1.8
C:/ruby/lib/ruby/1.8/i386-mswin32

Chris Hulan

2/6/2008 8:16:00 PM

0

On Feb 5, 5:22 pm, Gerry Ford <w...@zaxfuuq.net> wrote:
> Chris Hulan wrote:
> > On Feb 4, 8:20 pm, Gerry Ford <w...@zaxfuuq.net> wrote:
> >> My second question is about the shebang line: #!
> >> I was surprised to find that it matters what's written here when using
> >> the windows platform. There is no env folder in the bin folder, so if
> >> that's a path, then it's a path to nowhere. What "should" the first
> >> line say?
> >> --
>
> > I don't think it does matter on windows.
> > To execute a ruby file (say by double-clicking) you need to have the
> > file associations
> > configured.
>
> > On *nix the shebang allows a similar function.
> > #!/usr/bin/env is not a path, it is the 'env' command in /usr/bin
> > #!/usr/bin/env ruby will find ruby on the PATH then execute it, saves
> > hard-coding the ruby path (but assumes env is in a standard location).
>
> Thanks all for responses.
>
> I do not have an 'env' command in /bin/, which is to say, when I type
> env into the dos prompt at ruby/bin/, I get "no such command" from dos.
> Maybe I'm in the wrong bin?
>
> This question appears to go to environmental variables. In the
> documentation, it suggests to type ruby -e 'puts $:' to see this
> information. As output, I get:
> C:/ruby/lib/ruby/site_ruby/1.8
> C:/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt
> C:/ruby/lib/ruby/site_ruby
> C:/ruby/lib/ruby/1.8
> C:/ruby/lib/ruby/1.8/i386-mswin32

env is a standard *nix command, it is not specific to ruby

You often see perl/python/shell scripts using it too.
If your on Windows it is ignored (unless your using cygwin, or
something similar?)
I don't usually out it in my scripts...

Tim Hunter

2/6/2008 8:45:00 PM

0

Gerry Ford wrote:
> Well, you sound friendly enough.

I'm very friendly. Just ask anybody.

> My second question is about the shebang line: #!
> I was surprised to find that it matters what's written here when using
> the windows platform. There is no env folder in the bin folder, so if
> that's a path, then it's a path to nowhere. What "should" the first
> line say?

I would've guessed that it didn't matter, but I tried

#! garbage

and was also surprised to learn Ruby terminates the program with the
message "test.rb:1: Can't exec garbage (fatal)".

So I looked at the source code. In the load_file() function in ruby.c,
there is code that inspects the first line in the script. If it starts
with "#!" then the line must also contain the word "ruby". If it
doesn't, then Ruby calls execv() to run the "program" that it assumes
follows the #!. When execv() fails, Ruby terminates the program.

If the #! is on the 2nd line, or if the first line is

#! <anything>ruby<anything>

then everything is copacetic. That's why

#! /usr/bin/env/ruby -w

works.

--
Posted via http://www.ruby-....

Chris Hulan

2/7/2008 6:36:00 AM

0

On Feb 6, 3:45 pm, Tim Hunter <rmag...@gmail.com> wrote:
> Gerry Ford wrote:
....
> I would've guessed that it didn't matter, but I tried
>
> #! garbage
>
> and was also surprised to learn Ruby terminates the program with the
> message "test.rb:1: Can't exec garbage (fatal)".
>
> So I looked at the source code. In the load_file() function in ruby.c,
> there is code that inspects the first line in the script. If it starts
> with "#!" then the line must also contain the word "ruby". If it
> doesn't, then Ruby calls execv() to run the "program" that it assumes
> follows the #!. When execv() fails, Ruby terminates the program.
>
....

Thanks, that is interesting