るりまサーチ

最速Rubyリファレンスマニュアル検索!
223件ヒット [201-223件を表示] (0.055秒)

別のキーワード

  1. _builtin file?
  2. _builtin file
  3. file path
  4. file truncate
  5. file open

ライブラリ

クラス

キーワード

検索結果

<< < 1 2 3 >>

CSV#add_row(row) -> self (44.0)

自身に row を追加します。

.../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
CSV.open("test.csv", "a") do |csv|
csv.puts(["5", "saburo", "kondo", "34"])
end

print File.read("test.csv")
# => id,fir...
...ro,tanaka,20
# 2,jiro,suzuki,18
# 3,ami,sato,19
# 4,yumi,adachi,21
# 5,saburo,kondo,34
//}

//emlist[例 CSV::Row を指定][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
CSV.open("test...
....csv", "a") do |csv|
row = CSV::Row.new(["id", "first name", "last name", "age"], ["5", "saburo", "kondo", "34"])
csv.add_row(row)
end

print File.read("test.csv")
# => "id", first name,last name,age
# 1,taro,tanaka,20
# 2,jiro,suzuki,18
# 3,ami,sato,19
# 4,yumi,adachi,21
# 5,sabu...

Proc#<<(callable) -> Proc (37.0)

self と引数を合成した Proc を返します。

...//emlist[例][ruby]{
f = proc { |x| x * x }
g = proc { |x| x + x }

# (3 + 3) * (3 + 3)
p (f << g).call(3) # => 36
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end
end

File
.write('testfile', <<~TEXT)
Hello,...
...World!
Hello, Ruby!
TEXT

pipeline = proc { |data| puts "word count: #{data.size}" } << WordScanner << File.method(:read)
pipeline.call('testfile') # => word count: 4
//}

@see Method#<<, Method#>>...

Dir#read -> String | nil (31.0)

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

...が close している場合に発生します。

//emlist[例][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...
<< < 1 2 3 >>