Re: non-static way to get the filename?

how i can not
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.

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.

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:

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

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

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

Pit C. wrote:

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

Peter S. 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