non-OO realpath, basename, dirname?

D

David Garamond

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
 
D

David Garamond

David said:
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
 
J

Jamis Buck

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
 
I

Ilmari Heikkinen

Hi,

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top