るりまサーチ

最速Rubyリファレンスマニュアル検索!
1006件ヒット [1-100件を表示] (0.067秒)
トップページ > クエリ:file[x] > クエリ:ruby[x] > クエリ:read[x]

別のキーワード

  1. _builtin file?
  2. _builtin file
  3. file truncate
  4. file ctime
  5. file atime

ライブラリ

クラス

モジュール

検索結果

<< 1 2 3 ... > >>

ARGF.class#file -> IO (18153.0)

現在開いている処理対象の File オブジェクト(または IO オブジェ クト)を返します。

...開いている処理対象の File オブジェクト(または IO オブジェ
クト)を返します。

$ echo "foo" > foo
$ echo "bar" > bar

$ ruby argf.rb foo bar

ARGF.file # => #<File:foo>
ARGF.read(5) # => "foo\nb"
ARGF.file # => #<File:bar>

ARGFが現在開いて...

Dir#read -> String | nil (18149.0)

ディレクトリストリームから次の要素を読み出して返します。最後の要素 まで読み出していれば nil を返します。

...][ruby]{
require 'tmpdir'

Dir.mktmpdir do |tmpdir|
File
.open("#{tmpdir}/test1.txt", "w") { |f| f.puts("test1") }
File
.open("#{tmpdir}/test2.txt", "w") { |f| f.puts("test2") }
Dir.open(tmpdir) do |d|
p d.read # => "."
p d.read # => ".."
p d.read # => "test1.txt"
p d.read...
...# => "test2.txt"
p d.read # => nil
end
end
//}...

CSV.read(path, options = Hash.new) -> [Array] | CSV::Table (18137.0)

CSV ファイルを配列の配列にするために使います。 headers オプションに偽でない値を指定した場合は CSV::Table オブジェクトを返します。

...必ず指定しなければなりません。

//emlist[例][ruby]{
require "csv"
require "pp"

File
.write("test.csv", <<CSV)
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV

pp CSV.read("test.csv")

# => [["id", "first name", "last name", "age"],
#...
...to", "19"],
# ["4", "yumi", "adachi", "21"]]
//}

//emlist[例][ruby]{
require "csv"

File
.write("test.csv", <<CSV)
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
CSV

table = CSV.read("test.csv", headers: true)
p table.class # => CSV::Table
p table[0...

File.readlink(path) -> String (15118.0)

シンボリックリンクのリンク先のパスを文字列で返します。

...XX 指定された path がシンボリックリンクでない場合や、リンクの読み取りに失敗した場合に発生します。

//emlist[例:][ruby]{
IO.write("testfile", "test")
File
.symlink("testfile", "testlink") # => 0
File
.readlink("testlink") # => "testfile"
//}...

File.world_readable?(path) -> Integer | nil (15112.0)

path が全てのユーザから読めるならばそのファイルのパーミッションを表す 整数を返します。そうでない場合は nil を返します。

...場合は nil を返します。

整数の意味はプラットフォームに依存します。

@param path パスを表す文字列か IO オブジェクトを指定します。

//emlist[例][ruby]{
m = File.world_readable?("/etc/passwd")
"%o" % m # => "644"
//}...

絞り込み条件を変える

FileTest.#readable?(file) -> bool (9225.0)

ファイルがカレントプロセスにより読み込み可能な時に真を返します。そうでない場合、ファイルが存在しない場合、あるいはシステムコールに失敗した場合などには false を返します。

...は false を返します。

@param file ファイル名を表す文字列を指定します。

//emlist[例][ruby]{
IO.write("testfile", "")
File
.chmod(0644, "testfile")
File
Test.readable?("testfile") # => true
File
.chmod(0200, "testfile")
File
Test.readable?("testfile") # => false
//}...

File.new(path, mode = "r", perm = 0666) -> File (9209.0)

path で指定されるファイルをオープンし、File オブジェクトを生成して 返します。

...File オブジェクトを生成して
返します。

path が整数の場合はファイルディスクリプタとして扱い、それに対応する
File
オブジェクトを生成して返します。IO.open と同じです。
ブロックを指定して呼び出した場合は、File...
...mlist[例: File.new による読み込みモードでのファイルオープン][ruby]{
f = File.new("testfile", "r")
f.class # => File
f.close
//}

//emlist[例: File.open による読み込みモードでのファイルオープン][ruby]{
f = File.open("testfile", "r")
f.class # => File
f.close...
...//}

//emlist[例: File.open による書き込みモードでのファイルオープン][ruby]{
File
.open("testfile", "w", 0755) { |f| f.print "test" }
File
.read("testfile") # => "test"
//}...

File.open(path, mode = "r", perm = 0666) -> File (9209.0)

path で指定されるファイルをオープンし、File オブジェクトを生成して 返します。

...File オブジェクトを生成して
返します。

path が整数の場合はファイルディスクリプタとして扱い、それに対応する
File
オブジェクトを生成して返します。IO.open と同じです。
ブロックを指定して呼び出した場合は、File...
...mlist[例: File.new による読み込みモードでのファイルオープン][ruby]{
f = File.new("testfile", "r")
f.class # => File
f.close
//}

//emlist[例: File.open による読み込みモードでのファイルオープン][ruby]{
f = File.open("testfile", "r")
f.class # => File
f.close...
...//}

//emlist[例: File.open による書き込みモードでのファイルオープン][ruby]{
File
.open("testfile", "w", 0755) { |f| f.print "test" }
File
.read("testfile") # => "test"
//}...

File.open(path, mode = "r", perm = 0666) {|file| ... } -> object (9209.0)

path で指定されるファイルをオープンし、File オブジェクトを生成して 返します。

...File オブジェクトを生成して
返します。

path が整数の場合はファイルディスクリプタとして扱い、それに対応する
File
オブジェクトを生成して返します。IO.open と同じです。
ブロックを指定して呼び出した場合は、File...
...mlist[例: File.new による読み込みモードでのファイルオープン][ruby]{
f = File.new("testfile", "r")
f.class # => File
f.close
//}

//emlist[例: File.open による読み込みモードでのファイルオープン][ruby]{
f = File.open("testfile", "r")
f.class # => File
f.close...
...//}

//emlist[例: File.open による書き込みモードでのファイルオープン][ruby]{
File
.open("testfile", "w", 0755) { |f| f.print "test" }
File
.read("testfile") # => "test"
//}...
<< 1 2 3 ... > >>