るりまサーチ

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

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

IO.write(path, string, **opts) -> Integer (18127.0)

path で指定されるファイルを開き、string を書き込み、 閉じます。

...[例][ruby]{
text = "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
IO.write("testfile", text) # => 66
IO.write("testfile", "0123456789", 20) #=> 10
IO.read("testfile")
# => "This is line one\nThi0123456789two\nThis is line three\nAnd so on...\n"
IO.write("test...
...file", "0123456789") #=> 10
IO.read("testfile") # => "0123456789"
//}

@see IO.binwrite...

IO.write(path, string, offset=nil, **opts) -> Integer (18127.0)

path で指定されるファイルを開き、string を書き込み、 閉じます。

...[例][ruby]{
text = "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
IO.write("testfile", text) # => 66
IO.write("testfile", "0123456789", 20) #=> 10
IO.read("testfile")
# => "This is line one\nThi0123456789two\nThis is line three\nAnd so on...\n"
IO.write("test...
...file", "0123456789") #=> 10
IO.read("testfile") # => "0123456789"
//}

@see IO.binwrite...

IO.binwrite(path, string, offset=nil) -> Integer (6125.0)

path で指定されるファイルを開き、string を書き込み、 閉じます。

...き込み、
閉じます。

ファイルを開くときの mode が "rb:ASCII-8BIT" で、バイナリモードが有効
である点以外は IO.write と同じです。

Kernel.#open と同様 path の先頭が "|" ならば、"|" に続くコマンドを実行し、コマンドの出力を標...
...り捨てます。

@param path ファイル名文字列
@param string 書き込む文字列
@param offset 書き込み開始位置

//emlist[例][ruby]{
# 8x8の真っ白なPNG画像データ。
png = 'iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAAAAADhZOFXAAAADklEQVQIW2P4DwUMlDEA98A/wTjP
QBoAAAAASUVORK5CYII=...
...49 48 44 52

# binwriteを使用した場合: どの環境でも正しく保存できる。
IO.binwrite('white.binmode.png', png)
puts IO.binread('white.binmode.png', 16).unpack('C*').map {|c| '%02x' % c }.join(' ')
# => 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52

# binwriteを使用しなか...

RakeFileUtils.nowrite_flag -> bool (6107.0)

この値が真の場合、実際のファイル書き込みをともなう操作は行いません。 そうでない場合、ファイル書き込みを行います。

...ァイル書き込みをともなう操作は行いません。
そうでない場合、ファイル書き込みを行います。

//emlist[][ruby]{
# Rakefile での記載例とする
task default: :sample_file_task

file :sample_file_task do |t|
RakeFileUtils.nowrite_flag # => false
end
//}...

RakeFileUtils.nowrite_flag=(flag) (6107.0)

実際に動作を行うかどうか設定します。

...。真を指定すると動作を実行しません。

//emlist[][ruby]{
# Rakefile での記載例とする

task default: :sample_file_task

file :sample_file_task do |t|
RakeFileUtils.nowrite_flag # => false
RakeFileUtils.nowrite_flag = true
RakeFileUtils.nowrite_flag # => true
end
//}...

絞り込み条件を変える

CSV.filter(input, options = Hash.new) {|row| ... } (37.0)

このメソッドは CSV データに対して Unix のツール群のようなフィルタを構築 するのに便利です。

...フォルト値は $/ です。

//emlist[例: input, output は初期値][ruby]{
# $ echo "header1,header2\nrow1_1,row1_2" > in.csv; ruby test.rb in.csv

require "csv"

options = { headers: true, return_headers: true, write_headers: true }

CSV.filter(options) do |row|
if row.header_row?
row...
...ist[例: input, output を指定する][ruby]{
require "csv"
content = <<EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
EOS

File.write('test.csv',content)
options = { headers: true, return_headers: true, write_headers: true }

CSV.filter(File.open("...

CSV.filter(input, output, options = Hash.new) {|row| ... } (37.0)

このメソッドは CSV データに対して Unix のツール群のようなフィルタを構築 するのに便利です。

...フォルト値は $/ です。

//emlist[例: input, output は初期値][ruby]{
# $ echo "header1,header2\nrow1_1,row1_2" > in.csv; ruby test.rb in.csv

require "csv"

options = { headers: true, return_headers: true, write_headers: true }

CSV.filter(options) do |row|
if row.header_row?
row...
...ist[例: input, output を指定する][ruby]{
require "csv"
content = <<EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
EOS

File.write('test.csv',content)
options = { headers: true, return_headers: true, write_headers: true }

CSV.filter(File.open("...

CSV.filter(options = Hash.new) {|row| ... } (37.0)

このメソッドは CSV データに対して Unix のツール群のようなフィルタを構築 するのに便利です。

...フォルト値は $/ です。

//emlist[例: input, output は初期値][ruby]{
# $ echo "header1,header2\nrow1_1,row1_2" > in.csv; ruby test.rb in.csv

require "csv"

options = { headers: true, return_headers: true, write_headers: true }

CSV.filter(options) do |row|
if row.header_row?
row...
...ist[例: input, output を指定する][ruby]{
require "csv"
content = <<EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
EOS

File.write('test.csv',content)
options = { headers: true, return_headers: true, write_headers: true }

CSV.filter(File.open("...

CSV.open(filename, mode = "rb", options = Hash.new) -> CSV (37.0)

このメソッドは IO オブジェクトをオープンして CSV でラップします。 これは CSV ファイルを書くための主要なインターフェイスとして使うことを意図しています。

...ェクトは多くのメソッドを IO や File に委譲します。

* IO#binmode
* IO#binmode?
* IO#close
* IO#close_read
* IO#close_write
* IO#closed?
* IO#eof
* IO#eof?
* IO#external_encoding
* IO#fcntl
* IO#fileno
* File#flock
* IO#flush
* IO#fsync
* IO#internal_...
...ons CSV.new のオプションと同じオプションを指定できます。

//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 = CSV.open("t...
...anaka" "age":"20">
//}

//emlist[例 読み取り・ブロック指定あり][ruby]{
require "csv"

users =<<-EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
EOS

File.write("test.csv", users)
CSV.open("test.csv", headers: true) do |csv|
csv.class #...
<< 1 2 3 ... > >>