Forum: Ruby Re: non-static way to get the filename?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Berger, Daniel (Guest)
on 2006-05-09 18:45
(Received via mailing list)
> 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.
Peter S. (Guest)
on 2006-05-10 10:25
(Received via mailing list)
> 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
Pit C. (Guest)
on 2006-05-10 11:11
(Received via mailing list)
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
Peter S. (Guest)
on 2006-05-10 11:36
(Received via mailing list)
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
This topic is locked and can not be replied to.