Non-static way to get the filename?

I'm confused. You're saying File.basename(file) is *too verbose*? Or
have I misunderstood?

You can't get much more terse than File.basename without getting cryptic
imho.

Regards,

Dan

This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.

ยทยทยท

-----Original Message-----
From: Peter Szinek [mailto:peter@rubyrailways.com]
Sent: Tuesday, May 09, 2006 7:07 AM
To: ruby-talk ML
Subject: non-static way to get the filename?

Hello all,

I am new to Ruby etc. etc. (all the usual disclaimer about
how i can not
code in Ruby yet etc), so probably because of this i was not able to
find something like

myFile.basename
resp myFile.anything_which_returns_a_sensible_filename_like_string

and not

File.basename(myFile)

which i find too verbose for Ruby.
By browsing the reference part of the PickAxe 2nd ed, i did not find
any alternative to File.basename. Can somebody help me with this?

I'm confused. You're saying File.basename(file) is *too verbose*? Or
have I misunderstood?

You can't get much more terse than File.basename without getting cryptic
imho.

Well, for me

file.basename

is not cryptic. Maybe for someone it is... However, consider this snippet:

1)
File.copy(File.join(INPUTDIR,File.basename(f)),
           File.join(OUTPUTDIR,File.basename(f))

For me it is too verbose, i would like to see something along the lines of

2)
File.copy(INPUTDIR, f.basename,
           OUTPUTDIR, f.basename)

(semantics: File.join the 1st param with the 2nd and the 3rd with the 4th and copy joined_1 to joined_2).

or even

3)
File.copy(File.join(INPUTDIR, f.basename),
           File.join(OUTPUTDIR, f.basename))

would be better,

Which example do you find more readable? Is 2) too cryptic for you? Well i have to say that coming from Java (or even Python - i am coming from both) there are *far more* cryptic things in Ruby than any code snippet in this thread.

Cheers,
Peter

Peter Szinek schrieb:

Well, for me

file.basename

is not cryptic. Maybe for someone it is...

Peter, this syntax is very nice, indeed. But remember that your "file" variable above is a string. I don't think it would a good idea to add an immense number of methods to the String class for all the things a string could possibly represent. The standard library "pathname" offers exactly the nice syntax you propose, but uses its own class for file names.

Regards,
Pit

Pit Capitain wrote:

Peter Szinek schrieb:

Well, for me

file.basename

is not cryptic. Maybe for someone it is...

Peter, this syntax is very nice, indeed. But remember that your "file" variable above is a string. I don't think it would a good idea to add an immense number of methods to the String class for all the things a string could possibly represent. The standard library "pathname" offers exactly the nice syntax you propose, but uses its own class for file names.

Yep, point taken (i wrote the reply assuming that "pathname" does not exist).

Of course it would not be a good idea to put file-specific stuff into the String class, but i have thought file is a File - only now i havenoticed it is not! Thx for pointing it out!

SG,
Peter