るりまサーチ

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

別のキーワード

  1. _builtin each
  2. _builtin each_line
  3. prime each
  4. each
  5. tsort tsort_each

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

IO#each_line(limit) -> Enumerator (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...

IO#each_line(limit) {|line| ... } -> self (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...

IO#each_line(limit, chomp: false) -> Enumerator (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}

@see $/, IO#gets...

IO#each_line(limit, chomp: false) {|line| ... } -> self (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}

@see $/, IO#gets...

IO#each_line(rs = $/) -> Enumerator (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...

絞り込み条件を変える

IO#each_line(rs = $/) {|line| ... } -> self (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...

IO#each_line(rs = $/, chomp: false) -> Enumerator (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}

@see $/, IO#gets...

IO#each_line(rs = $/, chomp: false) {|line| ... } -> self (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}

@see $/, IO#gets...

IO#each_line(rs, limit) -> Enumerator (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...

IO#each_line(rs, limit) {|line| ... } -> self (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...

絞り込み条件を変える

IO#each_line(rs, limit, chomp: false) -> Enumerator (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}

@see $/, IO#gets...

IO#each_line(rs, limit, chomp: false) {|line| ... } -> self (15114.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...uby]{
IO.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...")
f = File.new("testfile")
f.each(chomp: true) { |line| p "#{f.lineno}: #{line}" }
# => "1: This is line one"
# "2: This is line two"
# "3: This is line three"
# "4: And so on..."
//}

@see $/, IO#gets...

Object::DATA -> File (56.0)

スクリプトの __END__ プログラムの終り以降をアクセスする File オブジェクト。

...イル ($0) を指します。

=== 例1
print DATA.gets # => 故人西辞黄鶴楼
print DATA.gets # => 烟花三月下揚州
print DATA.gets # => 孤帆遠影碧空尽
print DATA.gets # => 唯見長江天際流
DATA.gets # => nil

__END__
故人西辞黄鶴楼...
...唯見長江天際流

=== 例2
sum = 0
DATA.each_line do |line|
sum += line.to_i
end

DATA.rewind
p DATA.gets # => "sum = 0¥n"

__END__
17
19
23
29
31

=== 例3
DATA.gets # => uninitialized constant DATA (NameError)

=== 例4...
...ファイル library.rb と app.rb の内容が以下であったとします。

library.rb:
print DATA.gets

__END__
data from library

app.rb:
require 'library.rb'

__END__
data from app

このときシェルから次を実行すると
$ ruby app.rb
結果は以...

Kernel$$stdin -> object (50.0)

標準入力です。

...le.open("/tmp/foo", "r")
gets
# 入力する
$stdin = STDIN # 元に戻す
//}

ただし、Kernel.#gets など、特定の組み込みメソッドは
$stdin オブジェクトにメソッドを転送して実装されています。
従って、Kernel.#gets などが正しく動...
...していなければいけません。

gets
, readline, readlines, getc, readchar, tell, seek,
pos=, rewind, fileno, to_io, eof, each_line, each_byte,
binmode, closed?

//emlist[例][ruby]{
$stdin = Object.new
def $stdin.gets
"foo"
end
p gets() # => "foo"
//}

自プロセスだけ...
...][ruby]{
stdin_old = $stdin.dup # 元の $stdin を保存する
$stdout.reopen("/tmp/foo") # $stdin を /tmp/foo にリダイレクトする
gets
# /tmp/foo から入力
$stdin.reopen stdin_old # 元に戻す
//}

$stdin はグローバルスコープです。...

IO (20.0)

基本的な入出力機能のためのクラスです。

...io_encoding」を参照して下さい。
以下がテキスト読み込みメソッドです。

* IO.foreach
* IO.readlines
* IO#each_line
* IO#lines
* IO#gets
* IO#getc
* IO#ungetc
* IO#read
* IO#readchar
* IO#readline
* IO#readlines

バイナリ読み込みメソッドは IO のエ...
...emlist{
メソッド 既にEOFだったら

IO#each_byte 何もしない
IO#getc nil
IO#gets nil
IO#read() ""
IO#read(length) nil
IO#read_nonblock EOFError
IO#readchar...
...は「io_encoding」を参照して下さい。
以下がテキスト読み込みメソッドです。

* IO.foreach
* IO.readlines
* IO#each_line
* IO#gets
* IO#getc
* IO#ungetc
* IO#read
* IO#readchar
* IO#readline
* IO#readlines

バイナリ読み込みメソッドは IO のエンコ...

絞り込み条件を変える

IO#each(limit) -> Enumerator (14.0)

IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。

...This is line one,This is line two,This is line three,And so on...")
f = File.new("testfile")
f.each(",", 10) { |line| p "#{f.lineno}: #{line}" }
# => "0: This is li"
# "1: ne one,"
# "1: This is li"
# "2: ne two,"
# "2: This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}

@see $/, IO#gets...
<< 1 2 > >>