Ruby 1.9.2 リファレンスマニュアル > ライブラリ一覧 > pathnameライブラリ > Pathnameクラス
クラスの継承リスト: Pathname < Object < Kernel < BasicObject
パス名をオブジェクト指向らしく扱うクラスです。
Pathname オブジェクトはパス名を表しており、ファイルやディレクトリそのものを表してはいません。 当然、存在しないファイルのパス名も扱えます。
絶対パスも相対パスも扱えます。
Pathname オブジェクトは immutable であり、自身を破壊的に操作するメソッドはありません。
Pathname のインスタンスメソッドには、ディレクトリのパスを返す Pathname#dirname のように、 文字列操作だけで結果を返すものもあれば、ファイルの中身を読み出す Pathname#read のように ファイルシステムにアクセスするものもあります。
Pathname オブジェクトの生成には、Pathname.new のほかに Kernel#Pathname も使えます。
Pathname.new("foo/bar") # => #<Pathname:foo/bar>
Pathname("foo/bar")     # => #<Pathname:foo/bar>
| 定義 | 説明 | |
|---|---|---|
| 
  getwd -> Pathname | カレントディレクトリを元に Pathname オブジェクトを生成します。 Pathname.new(Dir.getwd) と同じです。 | |
| 
  glob(pattern, flags=0) -> [Pathname] | ワイルドカードの展開を行なった結果を、 Pathname オブジェクトの配列として返します。 | |
| 
  new(path) -> Pathname
   | 文字列 path を元に Pathname オブジェクトを生成します。 | |
| 定義 | 説明 | |
|---|---|---|
| 
  self + other -> Pathname
   | パス名を連結します。つまり、other を self からの相対パスとした新しい Pathname オブジェクトを生成して返します。 | |
| 
  self <=> other -> bool
   | パス名を比較します。other と同じなら 0 を、ASCII順で self が大きい場合 は正、other が大きい場合は負を返します。大文字小文字は区別されます。 other は Pathname オブジェクトでなければなりません。 | |
| 
  self == other -> bool | パス名を比較し、 other と同じなら真を返します。大文字小文字は区別されます。 other は Pathname オブジェクトでなければなりません。 | |
| 
  absolute? -> bool
   | self が絶対パス指定であれば真を返します。 | |
| 
  ascend { |pathname| ... }
   | self のパス名から親方向に辿っていったときの各パス名を新しい Pathname オ ブジェクトとして生成し、ブロックへの引数として渡して実行します。 | |
| 
  atime -> Time
   | File.atime(self.to_s) を渡したものと同じです。 | |
| 
  basename(suffix = "") -> Pathname
   | Pathname.new(File.basename(self.to_s, suffix)) と同じです。 | |
| 
  binread(*args)
   | IO.binread(self.to_s, *args)と同じです。 | |
| 
  blockdev? -> bool
   | FileTest.blockdev?(self.to_s) と同じです。 | |
| 
  chardev? -> bool
   | FileTest.chardev?(self.to_s) と同じです。 | |
| 
  children(with_directory = true) -> [Pathname]
   | self 配下にあるパス名(Pathnameオブジェクト)の配列を返します。 | |
| 
  chmod(mode) -> Integer
   | File.chmod(mode, self.to_s) と同じです。 | |
| 
  chown(owner, group) -> Integer
   | File.chown(owner, group, self.to_s) と同じです。 | |
| 
  cleanpath(consider_symlink = false) -> Pathname
   | 余計な "."、".." や "/" を取り除いた新しい Pathname オブジェクトを返します。 | |
| 
  ctime -> Time
   | File.ctime(self.to_s) を渡したものと同じです。 | |
| 
  unlink | self が指すディレクトリあるいはファイルを削除します。 | |
| 
  descend { |pathname| ... }
   | self のパス名の親から子供へと辿っていったときの各パス名を新しい Pathname オブジェクトとして生成し、ブロックへの引数として渡して実行しま す。 | |
| 
  directory? -> bool
   | FileTest.directory?(self.to_s) と同じです。 | |
| 
  dirname -> Pathname
   | Pathname.new(File.dirname(self.to_s)) と同じです。 | |
| 
  each_child(with_directory = true) -> Enumerator | self.children(with_directory).each と同じです。 | |
| 
  each_entry {|pathname| ... }
   | Dir.foreach(self.to_s) {|f| yield Pathname.new(f) } と同じです。 | |
| 
  each_filename {|v| ... } -> nil
   | self のパス名要素毎にブロックを実行します。 | |
| 
  each_line(*args, &block)
   | IO.foreach(self.to_s, *args, &block) と同じです。 | |
| 
  entries
   | Dir.entries(self.to_s) と同じです。 | |
| 
  executable? -> bool
   | FileTest.executable?(self.to_s) と同じです。 | |
| 
  executable_real? -> bool
   | FileTest.executable_real?(self.to_s) と同じです。 | |
| 
  exist? -> bool
   | FileTest.exist?(self.to_s) と同じです。 | |
| 
  expand_path(default_dir = '.') -> Pathname
   | Pathname.new(File.expand_path(self.to_s, *args)) と同じです。 | |
| 
  extname -> String
   | File.extname(self.to_s) と同じです。 | |
| 
  file? -> bool
   | FileTest.file?(self.to_s) と同じです。 | |
| 
  find {|pathname| ...}
   | self 配下のすべてのファイルやディレクトリを 一つずつ引数 pathname に渡してブロックを実行します。 | |
| 
  fnmatch(pattern, *args) -> bool
   | File.fnmatch(pattern, self.to_s, *args) と同じです。 | |
| 
  fnmatch?(pattern, *args) -> bool
   | File.fnmatch?(pattern, self.to_s, *args) と同じです。 | |
| 
  foreach(*args, &block)
   | このメソッドは obsolete です。 each_line か each_entry を使ってください。 | |
| 
  ftype -> String
   | File.ftype(self.to_s) と同じです。 | |
| 
  grpowned? -> bool
   | FileTest.grpowned?(self.to_s) と同じです。 | |
| 
  hash -> Fixnum
   | ハッシュ値を返します。 | |
| 
  join(*args) -> Pathname
   | 与えられたパス名を連結します。 | |
| 
  lchmod(mode) -> Integer
   | File.lchmod(mode, self.to_s) と同じです。 | |
| 
  lchown(owner, group) -> Integer
   | File.lchown(owner, group, self.to_s) と同じです。 | |
| 
  lstat -> File::Stat
   | File.lstat(self.to_s) と同じです。 | |
| 
  make_link(old)
   | File.link(old, self.to_s) と同じです。 | |
| 
  make_symlink(old)
   | File.symlink(old, self.to_s) と同じです。 | |
| 
  mkdir(*args)
   | Dir.mkdir(self.to_s, *args) と同じです。 | |
| 
  mkpath
   | FileUtils.mkpath(self.to_s) と同じです。 | |
| 
  mountpoint? -> bool
   | self がマウントポイントであれば真を返します。 | |
| 
  mtime -> Time
   | File.mtime(self.to_s) を渡したものと同じです。 | |
| 
  open(mode = 'r', perm = 0666) -> File | File.open(self.to_s, *args, &block) と同じです。 | |
| 
  opendir(&block)
   | Dir.open(self.to_s, &block) と同じです。 | |
| 
  owned? -> bool
   | FileTest.owned?(self.to_s) と同じです。 | |
| 
  parent -> Pathname
   | self の親ディレクトリを指す新しい Pathname オブジェクトを返します。 | |
| 
  pipe? -> bool
   | FileTest.pipe?(self.to_s) と同じです。 | |
| 
  read(*args) -> String | nil
   | IO.read(self.to_s, *args)と同じです。 | |
| 
  readable? -> bool
   | FileTest.readable?(self.to_s) と同じです。 | |
| 
  readable_real? -> bool
   | FileTest.readable_real?(self.to_s) と同じです。 | |
| 
  readlines(*args)
   | IO.readlines(self.to_s, *args)と同じです。 | |
| 
  readlink -> Pathname
   | Pathname.new(File.readlink(self.to_s)) と同じです。 | |
| 
  realdirpath(basedir = nil) -> Pathname
   | Pathname#realpath とほぼ同じで、最後のコンポーネントは実際に 存在しなくてもエラーになりません。 | |
| 
  realpath(basedir = nil) -> Pathname | 余計な "."、".." や "/" を取り除いた新しい Pathname オブジェクトを返します。 | |
| 
  relative? -> bool
   | self が相対パス指定であれば真を返す。 | |
| 
  relative_path_from(base_directory) -> Pathname
   | base_directory から self への相対パスを求め、その内容の新しい Pathname オブジェクトを生成して返します。 | |
| 
  rename(to) -> 0
   | File.rename(self.to_s, to) と同じです。 | |
| 
  rmdir
   | Dir.rmdir(self.to_s) と同じです。 | |
| 
  rmtree
   | FileUtils.rm_r(self.to_s) と同じです。 | |
| 
  root? -> bool
   | self がルートディレクトリであれば真を返します。判断は文字列操作によっ て行われ、ファイルシステムはアクセスされません。 | |
| 
  setgid? -> bool
   | FileTest.setgid?(self.to_s) と同じです。 | |
| 
  setuid? -> bool
   | FileTest.setuid?(self.to_s) と同じです。 | |
| 
  size -> Integer
   | FileTest.size(self.to_s) と同じです。 | |
| 
  size? -> bool
   | FileTest.size?(self.to_s) と同じです。 | |
| 
  socket? -> bool
   | FileTest.socket?(self.to_s) と同じです。 | |
| 
  split -> Array
   | File.split(self.to_s) と同じです。 | |
| 
  stat -> File::Stat
   | File.stat(self.to_s) と同じです。 | |
| 
  sticky? -> bool
   | FileTest.sticky?(self.to_s) と同じです。 | |
| 
  sub(pattern, replace) -> Pathname | self を表現するパス文字列に対して sub メソッドを呼び出し、その結果を内 容とする新しい Pathname オブジェクトを生成し、返します。 cf. String#sub | |
| 
  sub_ext(replace) -> Pathname
   | 拡張子を与えられた文字列で置き換えた Pathname オブジェクト返します。 | |
| 
  symlink? -> bool
   | FileTest.symlink?(self.to_s) と同じです。 | |
| 
  sysopen(*args)
   | IO.sysopen(self.to_s, *args)と同じです。 | |
| 
  to_path -> String
   | File.open などの引数に渡す際に呼ばれるメソッドです。 Pathname オブジェ クトにおいては、 to_s と同じです。 | |
| 
  to_s -> String
   | パス名を文字列で返します。 | |
| 
  truncate(length) -> 0
   | File.truncate(self.to_s, length) と同じです。 | |
| 
  utime(atime, mtime) -> Integer
   | File.utime(atime, mtime, self.to_s) と同じです。 | |
| 
  world_readable? -> bool
   | FileTest.world_readable?(self.to_s) と同じです。 | |
| 
  world_writable? -> bool
   | FileTest.world_writable?(self.to_s) と同じです。 | |
| 
  writable? -> bool
   | FileTest.writable?(self.to_s) と同じです。 | |
| 
  writable_real? -> bool
   | FileTest.writable_real?(self.to_s) と同じです。 | |
| 
  zero? -> bool
   | FileTest.zero?(self.to_s) と同じです。 | |
| 定義 | 説明 | |
|---|---|---|
| 
  SEPARATOR_PAT
   | パス名のなかのディレクトリを区切る部分にマッチする正規表現です。 | |
| 
  TO_PATH
   | 内部的に使っている定数です。利用者が使うことはありません。 | |
!
!=
=~
__id__
__send__
_dump
class
clone
dclone
display
enum_for
equal?
extend
freeze
frozen?
initialize
initialize_copy
inspect
instance_eval
instance_exec
instance_of?
instance_variable_defined?
instance_variable_get
instance_variable_set
instance_variables
is_a?
marshal_dump
marshal_load
method
method_missing
methods
must_be
must_be_close_to
must_be_empty
must_be_instance_of
must_be_kind_of
must_be_nil
must_be_same_as
must_be_within_epsilon
must_equal
must_include
must_match
must_raise
must_respond_to
must_send
must_throw
nil?
pretty_inspect
pretty_print
pretty_print_cycle
pretty_print_inspect
pretty_print_instance_variables
private_methods
protected_methods
public_methods
remove_instance_variable
respond_to?
respond_to_missing?
singleton_class
singleton_method_added
singleton_method_removed
singleton_method_undefined
singleton_methods
taint
tainted?
tap
to_a
to_ary
to_hash
to_int
to_io
to_proc
to_regexp
to_str
to_yaml
to_yaml_properties
to_yaml_style
trust
untaint
untrust
untrusted?
wont_be
wont_be_close_to
wont_be_empty
wont_be_instance_of
wont_be_kind_of
wont_be_nil
wont_be_same_as
wont_be_within_epsilon
wont_equal
wont_include
wont_match
wont_respond_to