[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

non-OO realpath, basename, dirname?

David Garamond

12/25/2004 3:33:00 AM

Is there a better way than below? (Note: I don't want to implement
realpath et al myself :-).

require 'pathname'

def realpath(p)
Pathname.new(p).realpath
end

def basename(p)
Pathname.new(p).basename
end

def dirname(p)
Pathname.new(p).dirname
end

Regards,
dave


3 Answers

David Garamond

12/25/2004 4:34:00 AM

0

David Garamond wrote:
> Is there a better way than below? (Note: I don't want to implement
> realpath et al myself :-).
>
[snip]
> Pathname.new(p).realpath
> Pathname.new(p).basename
> Pathname.new(p).dirname

Sorry, that should've been:

Pathname.new(p).realpath.to_s
Pathname.new(p).basename.to_s
Pathname.new(p).dirname.to_s

Regards,
dave


Jamis Buck

12/25/2004 5:44:00 AM

0

On 12:32 Sat 25 Dec , David Garamond wrote:
> Is there a better way than below? (Note: I don't want to implement
> realpath et al myself :-).
>
> require 'pathname'
>
> def realpath(p)
> Pathname.new(p).realpath
> end
>
> def basename(p)
> Pathname.new(p).basename
> end
>
> def dirname(p)
> Pathname.new(p).dirname
> end
>
> Regards,
> dave
>
>

For basename and dirname:

File.basename(p)
File.dirname(p)

Dunno for realpath :(

- Jamis

--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck...



Ilmari Heikkinen

12/25/2004 5:56:00 AM

0

Hi,

On 25.12.2004, at 06:33, David Garamond wrote:
> Pathname.new(p).basename.to_s
> Pathname.new(p).dirname.to_s

File.basename(p)
File.dirname(p)

> Pathname.new(p).realpath.to_s

File.expand_path(p), though it doesn't follow links. The #realpath
implementation in pathname.rb does the resolving by itself, so it seems
you have to make your own function :I


-Ilmari