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
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?
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.
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.
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!