diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-17 05:59:29 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-06-17 05:59:29 +0000 |
commit | 7d274ff6fbb97c3ac8ee0ce6903f0e77b05e0b07 (patch) | |
tree | 07625bbabe206f8454006d2488d9c8dc7b74260d /lib/pathname.rb | |
parent | eeda97f8e39354d8a57c5bdd3ab0b5e4bda22a0d (diff) |
* lib/pathname.rb (Kernel#Pathname): new method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/pathname.rb')
-rw-r--r-- | lib/pathname.rb | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/pathname.rb b/lib/pathname.rb index 843d801305..7eaa82b7ce 100644 --- a/lib/pathname.rb +++ b/lib/pathname.rb @@ -182,12 +182,22 @@ # information. In some cases, a brief description will follow. # class Pathname + + # :stopdoc: + if RUBY_VERSION < "1.9" + TO_PATH = :to_str + else + # to_path is implemented so Pathname objects are usable with File.open, etc. + TO_PATH = :to_path + end + # :startdoc: + # # Create a Pathname object from the given String (or String-like object). # If +path+ contains a NUL character (<tt>\0</tt>), an ArgumentError is raised. # def initialize(path) - path = path.to_path if path.respond_to? :to_path + path = path.__send__(TO_PATH) if path.respond_to? TO_PATH @path = path.dup if /\0/ =~ @path @@ -229,7 +239,7 @@ class Pathname end # to_path is implemented so Pathname objects are usable with File.open, etc. - alias to_path to_s + alias_method TO_PATH, :to_s def inspect # :nodoc: "#<#{self.class}:#{@path}>" @@ -491,9 +501,10 @@ class Pathname # Pathname.new("/usr/bin/ruby").each_filename {|filename| ... } # # yields "usr", "bin", and "ruby". # - def each_filename # :yield: s + def each_filename # :yield: filename prefix, names = split_names(@path) names.each {|filename| yield filename } + nil end # Iterates over and yields a new Pathname object @@ -514,6 +525,8 @@ class Pathname # # It doesn't access actual filesystem. # + # This method is available since 1.8.5. + # def descend vs = [] ascend {|v| vs << v } @@ -539,6 +552,8 @@ class Pathname # # It doesn't access actual filesystem. # + # This method is available since 1.8.5. + # def ascend path = @path yield self @@ -1031,3 +1046,13 @@ class Pathname # * mixed * end end end + +module Kernel + # create a pathname object. + # + # This method is available since 1.8.5. + def Pathname(path) # :doc: + Pathname.new(path) + end + private :Pathname +end |