別のキーワード
ライブラリ
- ビルトイン (132)
- csv (108)
-
irb
/ context (24) - readline (12)
- stringio (24)
クラス
- CSV (108)
- IO (72)
-
IRB
:: Context (24) - StringIO (24)
キーワード
-
$ _ (12) -
$ stdin (12) -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) -
NEWS for Ruby 2
. 4 . 0 (9) -
NEWS for Ruby 2
. 7 . 0 (6) -
NEWS for Ruby 3
. 1 . 0 (4) - gets (24)
-
header
_ row? (12) - irb (12)
- lineno (12)
- readlines (120)
- rewind (12)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 4 feature (12) - shift (12)
-
unconverted
_ fields? (12) -
use
_ readline (12) -
use
_ readline? (12)
検索結果
先頭5件
-
Readline
. # readline(prompt = "" , add _ hist = false) -> String | nil (35293.0) -
prompt を出力し、ユーザからのキー入力を待ちます。 エンターキーの押下などでユーザが文字列を入力し終えると、 入力した文字列を返します。 このとき、add_hist が true であれば、入力した文字列を入力履歴に追加します。 何も入力していない状態で EOF(UNIX では ^D) を入力するなどで、 ユーザからの入力がない場合は nil を返します。
...:
require "readline"
input = Readline.readline
(プロンプトなどは表示せずに、入力待ちの状態になります。
ここでは「abc」を入力後、エンターキーを押したと想定します。)
abc
p input # => "abc"
input = Readline.readline("> ")
(">"......p input # => "ls"
input = Readline.readline("> ", true)
(">"を表示し、入力待ちの状態になります。
ここでは「cd」を入力後、エンターキーを押したと想定します。)
> cd
p input # => "cd"
input = Readline.readline("> ", true)
(">"を表示...... ruby インタプリタが終了し、端末状態を復帰しません。
これを回避するための例を2つ挙げます。
例: ^CによるInterrupt例外を捕捉して、端末状態を復帰する。
require 'readline'
stty_save = `stty -g`.chomp
begin
while buf = Readline.r... -
Kernel
. # readline(rs = $ / ) -> String (18149.0) -
ARGFから一行読み込んで、それを返します。 行の区切りは引数 rs で指定した文字列になります。
...生します。
@raise EOFError readline でファイル末端(EOF)を検出すると発生します。
//emlist[例][ruby]{
# ---main.rb---
ARGV << 'b.txt' << 'c.txt'
p readline #=> "hello\n"
p readline(nil) #=> "it\ncommon\n"
p readline("") #=> "ARGF\n\n"
p readline('、') #=> "スクリプトに......定した引数 (Object::ARGV を参照) をファイル名と\nみなして、"
p readline #=> "それらのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。 \n"
p readline # end of file reached (EOFError)
# --- b.txt ---
hello
it
common
# --- c.txt ---
ARGF......# スクリプトに指定した引数 (Object::ARGV を参照) をファイル名と
# みなして、それらのファイルを連結した 1 つの仮想ファイルを表すオブジェクトです。
//}
@see $/,ARGF,Kernel.#readlines,Kernel.#gets... -
StringIO
# readline(rs = $ / ) -> String (18131.0) -
自身から 1 行読み込んで、その文字列を返します。
...行読み込んで、その文字列を返します。
文字列の終端に到達した時には、例外 EOFError を発生させます。
IO#readline と違い読み込んだ文字列を変数 $_ にセットしません。
@param rs 行の区切りを文字列で指定します。rs に nil......ンされていなければ発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge\nfoo\nbar\n")
a.readline #=> "hoge\n"
a.readline(nil) #=> "foo\nbar\n"
a.readline #=> EOFError が発生する
//}
@... -
CSV
# readline -> Array | CSV :: Row (15119.0) -
String や IO をラップしたデータソースから一行だけ読み込んで フィールドの配列か CSV::Row のインスタンスを返します。
...しない場合は配列を返します。
ヘッダを使用する場合は CSV::Row を返します。
//emlist[例][ruby]{
require "csv"
csv = CSV.new(DATA.read)
csv.readline # => ["header1", "header2"]
csv.readline # => ["row1_1", "row1_2"]
__END__
header1,header2
row1_1,row1_2
//}... -
IRB
:: Context # use _ readline -> bool | nil (6154.0) -
readline を使うかどうかを返します。
...
readline を使うかどうかを返します。
@return 戻り値よって以下のように動作します。
: true
readline ライブラリを使う
: false
readline ライブラリを使わない
: nil
inf-ruby-mode 以外で readline ライブラリを利用しようとする (......デフォルト)
動作を変更するためには .irbrc ファイル中で IRB.conf[:USE_READLINE] の設
定や irb 起動時に --readline オプション、--noreadline オプションの指定
を行います。... -
IRB
:: Context # use _ readline? -> bool | nil (6154.0) -
readline を使うかどうかを返します。
...
readline を使うかどうかを返します。
@return 戻り値よって以下のように動作します。
: true
readline ライブラリを使う
: false
readline ライブラリを使わない
: nil
inf-ruby-mode 以外で readline ライブラリを利用しようとする (......デフォルト)
動作を変更するためには .irbrc ファイル中で IRB.conf[:USE_READLINE] の設
定や irb 起動時に --readline オプション、--noreadline オプションの指定
を行います。... -
Kernel
. # readlines(rs = $ / ) -> [String] (6118.0) -
ARGFを Kernel.#gets(rs) でEOFまで読み込んで、その各行を要素としてもつ配列を返します。 行の区切りは引数 rs で指定した文字列になります。
...mlist[main.rb][ruby]{
ARGV << 'b.txt' << 'b.txt'
p readlines #=> ["hello\n", "it\n", "\n", "common\n", "hello\n", "it\n", "\n", "common\n"]
ARGV << 'b.txt' << 'b.txt'
p readlines(nil) #=> ["hello\nit\n\ncommon\n", "hello\nit\n\ncommon\n"]
ARGV << 'b.txt' << 'b.txt'
p readlines("") #=> ["h......ello\nit\n\n", "common\n", "hello\nit\n\n", "common\n"]
ARGV << 'b.txt' << 'b.txt'
p readlines('it') #=> ["hello\nit", "\n\ncommon\n", "hello\nit", "\n\ncommon\n"]
p readlines #=> []
//}
//emlist[b.txt][ruby]{
hello
it
common
//}
@see $/,ARGF,Kernel.#gets, Kernel.#readline... -
IO
# readlines(limit , chomp: false) -> [String] (6112.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
...れていなければ発生します。
//emlist[例][ruby]{
IO.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines(3) } # => ["lin", "e1,", "\n", "lin", "e2,", "\n", "li......//emlist[例: rsを取り除く(chomp = true)][ruby]{
IO.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # => ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\n... -
IO
# readlines(rs = $ / , chomp: false) -> [String] (6112.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
...れていなければ発生します。
//emlist[例][ruby]{
IO.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines(3) } # => ["lin", "e1,", "\n", "lin", "e2,", "\n", "li......//emlist[例: rsを取り除く(chomp = true)][ruby]{
IO.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # => ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\n...