Just a small language question

Why does Ruby do single quotes around package names?

Why not just:

require somepackage

Just a little question…

Bob

/ do not send to my e-mail address /

You can. However, what does “require somepackage” really
mean?

You’re trying to require the filename contained within the
locally scoped variable “somepackage”.

For example:

somepackage = 'a_package_name'
require somepackage

Effectively, the same as:

require 'a_package_name'

Does this make sense?

– Dossy

– Dossy

···

On 2002.07.19, Bob X bobx@linuxmail.org wrote:

Why does Ruby do single quotes around package names?

Why not just:

require somepackage

Just a little question…


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Hello –

Why does Ruby do single quotes around package names?

It doesn’t have to be single quotes – it can be double quotes or any
other quoting mechanism, or a variable, as long as it evaluates to a
string.

Why not just:

require somepackage

require and load are looking for files, so (even though there’s a bit
of magic involved in searching and adding extensions) basically what’s
needed is a string.

When you get to the ‘include’ stage, you generally supply an actual
module name, not quoted:

include SomeModule

David

···

On Fri, 19 Jul 2002, Bob X wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Because the package name represents a file name which could have spaces,
etc.

Assuming:

“my cool ruby library.rb”

you would have:

require ‘my cool ruby library’

So this would be problematic:

require my cool ruby library

-rich

···

-----Original Message-----
From: Bob X [mailto:bobx@linuxmail.org]
Sent: Thursday, July 18, 2002 4:30 PM
To: ruby-talk ML
Subject: Just a small language question…

Why does Ruby do single quotes around package names?

Why not just:

require somepackage

Just a little question…

Bob

/ do not send to my e-mail address /

while i think the other posts effectivly answered your question. i have
a require related question myself. hope you don’t mind.

given a directory tree:

pdir
programP.rb
adir
a1.rb
a2.rb
programA.rb

and the files as such:

programP.rb:
require ‘adir/a1’

a1.rb:
require ‘adir/a2’

a2.rb:

dosn’t matter

programA.rb:
require ‘a1’

%cd pdir
%ruby programP.rb
%cd adir
%ruby programA.rb
./a1.rb:1:in ‘require’:No such file to load – adir/a2 (Load Error)

to get programA.rb to work you have to remove adir/ from the require in
a1.rb, but then programP.rb stops working. this is annoying as i would
think the local directory hiearchy to the required file should be
checked first for a match, and only after that, if at all, should the
main file’s hiearchy be checked. as it now stands, regardless of
programA, if i decided i just wanted to move programP somewhere else,
say into adir for example, i not only need to modify its require paths,
but i am forced to modify each of those required file’s require paths.
and that’s just not natural.

~transami

···

On Thu, 2002-07-18 at 14:30, Bob X wrote:

Why does Ruby do single quotes around package names?

Why not just:

require somepackage

Just a little question…

Bob

/ do not send to my e-mail address /


~transami

(") dobee dobee do…
\v/
^ ^

Because then you’d be introducing (more) syntax that’s different from
the usual requirements of Ruby programs. We already have def/end,
if/else/end, etc.

You don’t mind having to quote other method arguments:

frobnozzle ‘blrpfst’

So why should ‘require’ be any different?

Remember, ‘require’ isn’t a reserved word or any special part of Ruby
syntax.

It’s just a method in module Kernel.

···

On Thursday 18 July 2002 01:30 pm, Bob X wrote:

Why does Ruby do single quotes around package names?

Why not just:

require somepackage


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE

Rich Kilmer wrote:

Because the package name represents a file name which could have spaces,
etc.

Assuming:

“my cool ruby library.rb”

you would have:

require ‘my cool ruby library’

So this would be problematic:

require my cool ruby library

-rich

Er…well Python and Perl (and I think Tcl) do not seem to have this worry?

And THAT, my friends, is THE BEST answer of all.

Require is a method, not a keyword.

I really like this language!

-rich

···

-----Original Message-----
From: Ned Konz [mailto:ned@bike-nomad.com]
Sent: Thursday, July 18, 2002 6:26 PM
To: ruby-talk ML
Subject: Re: Just a small language question…

So why should ‘require’ be any different?

Remember, ‘require’ isn’t a reserved word or any special part of Ruby
syntax.

It’s just a method in module Kernel.


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE

Hello –

Rich Kilmer wrote:

Because the package name represents a file name which could have spaces,
etc.

Assuming:

“my cool ruby library.rb”

you would have:

require ‘my cool ruby library’

So this would be problematic:

require my cool ruby library

-rich

Er…well Python and Perl (and I think Tcl) do not seem to have this worry?

File and/or module-loading works differently in different languages,
so it’s hard to compare point for point; but I don’t think there’s any
where you can use an unquoted filename that has a space in it.

$ echo 1 > Some\ File.pm
$ perl -e ‘require “Some File.pm”’ # OK
$ perl -e ‘require Some File.pm’ # Perl isn’t this magic :slight_smile:
syntax error at -e line 1, near "require Some File"
Execution of -e aborted due to compilation errors.

David

···

On Fri, 19 Jul 2002, Bob X wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Rich Kilmer wrote:

Because the package name represents a file name which could have spaces,
etc.

Er…well Python and Perl (and I think Tcl) do not seem to have this
worry?

Hmm. Let’s back up here.

require takes a file name. In my book, that’s
data. Leave it unquoted, and it looks like a
variable name or something.

Blank spaces are not the entire issue. Even if
we disallowed spaces in names, how would you
distinguish between the file name and some other
kind of expression?

Contrived example (I’m good at those sometimes).
In Ruby, both these are valid:

class Blah
attr_accessor :txt
end

file = Blah.new
file.name = “foo.bar”

require “file.txt” # Read from "file.txt"
require file.txt # Read from “foo.bar”

As for automagically converting an identifier or
expression into a string… I’d be surprised if
Python did it. Less surprised if Perl did. Not
much surprised if Tcl did – seems like every
bloody thing in the universe is a string in Tcl,
isn’t it?

Anyhow, I wouldn’t want this to work. It would
just be too weird. Next thing, somebody would want
’open’ to work the same way:

file = File.open(myfile.txt)

<tongue_in_cheek>
Unquoted file names work in DOS batch files.
That’s because they quote the variable names
instead. And it probably would have worked in
Palo Alto BASIC, circa 1978, which had perhaps
the worst string handling since machine language
was king.
</tongue_in_cheek>

Hal

went out

···

----- Original Message -----
From: “Bob X” bobx@linuxmail.org
Newsgroups: comp.lang.ruby
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, July 18, 2002 4:30 PM
Subject: Re: Just a small language question…

% tclsh
% package require Cool Package
expected version number but got “Package”
%

-Martin

···

On Fri, Jul 19, 2002 at 06:30:19AM +0900, Bob X wrote:

Rich Kilmer wrote:

Because the package name represents a file name which could have spaces,
etc.

Assuming:

“my cool ruby library.rb”

you would have:

require ‘my cool ruby library’

So this would be problematic:

require my cool ruby library

-rich

Er…well Python and Perl (and I think Tcl) do not seem to have this worry?