Project

General

Profile

Feature #1046

request: ability to run without specifying .rb

Added by rogerdpack (Roger Pack) over 8 years ago. Updated over 6 years ago.

Status:
Rejected
Priority:
Normal
Target version:
-
[ruby-core:21550]

Description

=begin
It would be nice to be able to use ruby [on windows, at least] via

ruby filename
when filename.rb exists
This is surprising that it does not work, as
ruby -rfilename filename.rb
does work without the .rb suffix for the -r parameter.

Thank you!
-=r
=end

History

#1 Updated by rogerdpack (Roger Pack) over 8 years ago

=begin
Speaking out loud, is there a reason why require does not require .rb suffix, and load does?
Thanks!
-=r
=end

#2 Updated by matz (Yukihiro Matsumoto) over 8 years ago

=begin
Hi,

In message "Re: [Feature #1046] request: ability to run without specifying .rb"
on Sun, 25 Jan 2009 05:42:16 +0900, Roger Pack redmine@ruby-lang.org writes:

|Speaking out loud, is there a reason why require does not require .rb suffix, and load does?
|Thanks!

require is to load "libraries", where load is to load "scripts". The
target of the load method might be configuration files, or anything
else from the specified path, but at least they are all Ruby scripts.
On the other hand, the require method loads Ruby libraries or dynamic
loading C implemented libraries reside in the load path. So it needs
file path extension to distinguish which kind of library to read.

And could you please tell me why you felt it's be nice to be able to
omit extension [on Windows]? The ruby command is invoked from command
line, which always shows extensions, unlike from Explorer.

                        matz.

=end

#3 Updated by jredville (Jim Deville) over 8 years ago

=begin

-----Original Message-----
From: Yukihiro Matsumoto [mailto:matz@ruby-lang.org]
Sent: Monday, January 26, 2009 6:44 AM
To: ruby-core@ruby-lang.org
Subject: Re: [Feature #1046] request: ability to run
without specifying .rb

Hi,

In message "Re: [Feature #1046] request: ability to
run without specifying .rb"
on Sun, 25 Jan 2009 05:42:16 +0900, Roger Pack writes:

|Speaking out loud, is there a reason why require does not require .rb
suffix, and load does?
|Thanks!

require is to load "libraries", where load is to load "scripts". The
target of the load method might be configuration files, or anything
else from the specified path, but at least they are all Ruby scripts.
On the other hand, the require method loads Ruby libraries or dynamic
loading C implemented libraries reside in the load path. So it needs
file path extension to distinguish which kind of library to read.

And could you please tell me why you felt it's be nice to be able to
omit extension [on Windows]? The ruby command is invoked from command
line, which always shows extensions, unlike from Explorer.

                                                    matz.

I tend to agree. If you really want to save the characters, why not make a .bat file like gem does, which calls "ruby file.rb". Then you can just call the batch file without the extension. Otherwise, tab completion is your friend :)

JD

=end

#4 Updated by rogerdpack (Roger Pack) over 8 years ago

=begin

And could you please tell me why you felt it's be nice to be able to
omit extension [on Windows]? The ruby command is invoked from command

The answer is perhaps unsatisfying. I find the convenience of not having to include the extension on 'require' commands very appealing and would like to extend its use. I can't think of a reason why this would hurt ruby. Are there any drawbacks? And it would be useful, at least for me. One less tab to hit. I don't want to start a fight but I'm just giving feedback. At times, in Linux it would be convenient, too [mostly when you type in the name of a ruby script, and then have to ponder for a second whether or not it has an extension, or hit tab several times to try and discover it].

Thanks for listening.
=end

#5 Updated by luislavena (Luis Lavena) over 8 years ago

=begin
On Mon, Jan 26, 2009 at 6:03 PM, Roger Pack redmine@ruby-lang.org wrote:

Issue #1046 has been updated by Roger Pack.

And could you please tell me why you felt it's be nice to be able to
omit extension [on Windows]? The ruby command is invoked from command

The answer is perhaps unsatisfying. I find the convenience of not having to include the extension on 'require' commands very appealing and would like to extend its use. I can't think of a reason why this would hurt ruby. Are there any drawbacks? And it would be useful, at least for me. One less tab to hit. I don't want to start a fight but I'm just giving feedback. At times, in Linux it would be convenient, too [mostly when you type in the name of a ruby script, and then have to ponder for a second whether or not it has an extension, or hit tab several times to try and discover it].

I wonder why you don't add .rb to PATHEXT and define the association
to make it automatically execute it for you?

I have several ruby scripts in my %HOME%\bin that are pure ruby, no
batch file around it and work perfectly.

Thanks for listening.

http://redmine.ruby-lang.org/issues/show/1046


http://redmine.ruby-lang.org

--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

=end

#6 Updated by matz (Yukihiro Matsumoto) over 8 years ago

=begin
Hi,

In message "Re: [Feature #1046] request: ability to run without specifying .rb"
on Tue, 27 Jan 2009 05:03:24 +0900, Roger Pack redmine@ruby-lang.org writes:

|The answer is perhaps unsatisfying.

You asked the reason behind load and require, and I answered. Then I
asked you to show the merit of changing Ruby which you haven't shown,
before asking me to change. Isn't it reasonable?

|I find the convenience of not having to include the extension on
|'require' commands very appealing and would like to extend its use.
|I can't think of a reason why this would hurt ruby. Are there any
|drawbacks?

I don't think it hurts Ruby much. But I think changing/adding feature
require something more than not-hurt-much. As I said before, typical
use-case of the load method is loading configuration file. If I have
a configuration file, I'd give it a extension for a configuration
file, even if it uses Ruby syntax.

|And it would be useful, at least for me. One less tab to
|hit. I don't want to start a fight but I'm just giving feedback. At
|times, in Linux it would be convenient, too [mostly when you type in
|the name of a ruby script, and then have to ponder for a second
|whether or not it has an extension, or hit tab several times to try
|and discover it].

This request has two problems: First, you are discussing about two
slightly different issues. Omitting extension in command lines, and
omitting extension in load method. You have to separate them.
Second, you made a proposal, but you haven't shown merits of adding
this new feature. In the follow-up, You just told us reduction of a
few tab hits as a merit. But I still feel it's little bit weak.

                        matz.

=end

#7 Updated by matz (Yukihiro Matsumoto) over 8 years ago

=begin
Hi,

In message "Re: Re: [Feature #1046] request: ability to run without specifying .rb"
on Tue, 27 Jan 2009 09:35:10 +0900, Roger Pack rogerdpack@gmail.com writes:

|Oh sorry--I meant that you would probably find my answer [that I am lazy and
|don't want to have to think when running ruby] as unsatisfying.

That's the point. I have been a Ruby user for last 15 years, and I
have never felt omitting extension help me being lazy. I am sure I am
lazier than you are here. In fact, I am too lazy to think about .rb
as a extension, it's only a part of file name unless it a library name
(target of require). So there must be something help you by omitting
extension. Could you explain how this help you to be lazy, unless you
are too lazy?

Tab issue is reasonable, but not strong enough, if I have "foo.rb",
when I type "fo" then hit tab, I will get "foo.rb" anyway. It's
highly dependent on how you choose file names.

                        matz.

=end

#8 Updated by nobu (Nobuyoshi Nakada) over 8 years ago

=begin
Hi,

At Thu, 29 Jan 2009 05:11:16 +0900,
Roger Pack wrote in :

|Oh sorry--I meant that you would probably find my answer [that I am lazy and
|don't want to have to think when running ruby] as unsatisfying.

That's the point. I have been a Ruby user for last 15 years, and I
have never felt omitting extension help me being lazy. I am sure I am
lazier than you are here. In fact, I am too lazy to think about .rb
as a extension, it's only a part of file name unless it a library name
(target of require). So there must be something help you by omitting
extension. Could you explain how this help you to be lazy, unless you
are too lazy?

Tab issue is reasonable, but not strong enough, if I have "foo.rb",
when I type "fo" then hit tab, I will get "foo.rb" anyway. It's
highly dependent on how you choose file names.

good answer :)

I like the suggestion to create a batch file [say r.bat] that handles
both cases that should work well.

What about the suggestion by Luis Lavena at ?

Another question:

Is there a way to do this from the command line?

require 2 files:

$ ruby -rrubygems -rfacets -e '3'
ruby: no such file to load -- facets (LoadError)

It's gem specific, and has gone in 1.9 as rubygems is built-in
now.

Also is there a way to do something like
$ ruby -e 'initialization code' filename_run_after.rb

ruby -e 'initialization code; load($0=ARGV.shift)' filename_run_after.rb

--
Nobu Nakada

=end

#9 Updated by ko1 (Koichi Sasada) over 8 years ago

  • Status changed from Open to Rejected
  • Assignee set to matz (Yukihiro Matsumoto)

=begin

=end

Also available in: Atom PDF