別のキーワード
ライブラリ
- ビルトイン (279)
- shell (6)
-
shell
/ command-processor (24) -
shell
/ filter (6) - zlib (22)
クラス
-
ARGF
. class (24) - IO (168)
- Shell (6)
-
Shell
:: CommandProcessor (24) -
Shell
:: Filter (6) - String (76)
-
Zlib
:: GzipReader (22)
モジュール
- Enumerable (11)
検索結果
先頭5件
-
String
# chomp(rs = $ / ) -> String (24340.0) -
self の末尾から rs で指定する改行コードを取り除いた文字列を生成して返します。 ただし、rs が "\n" ($/ のデフォルト値) のときは、 実行環境によらず "\r", "\r\n", "\n" のすべてを改行コードとみなして取り除きます。
...][ruby]{
p "foo\n".chomp # => "foo"
p "foo\n".chomp("\n") # => "foo"
p "foo\r\n".chomp("\r\n") # => "foo"
$/ = "\n" # デフォルト値と同じ
p "foo\r".chomp # => "foo"
p "foo\r\n".chomp # => "foo"
p "foo\n".chomp # => "foo"
p "foo\n\r".chomp # => "foo\n"
p "strin......g\n".chomp(nil) # => "string\n"
p "foo\r\n\n".chomp("") # => "foo"
p "foo\n\r\n".chomp("") # => "foo"
p "foo\n\r\r".chomp("") # => "foo\n\r\r"
//}
@see String#chomp!
@see String#chop......g\n".chomp(nil) # => "string\n"
p "foo\r\n\n".chomp("") # => "foo"
p "foo\n\r\n".chomp("") # => "foo"
p "foo\n\r\r".chomp("") # => "foo\n\r\r"
//}
@see String#chomp!
@see String#chop
@see String#delete_suffix... -
String
# chomp!(rs = $ / ) -> self | nil (12322.0) -
self の末尾から rs で指定する改行コードを取り除きます。 ただし rs が "\n" ($/ のデフォルト値) のときは、 実行環境によらず "\r", "\r\n", "\n" のすべてを改行コードとみなして取り除きます。
...n chomp! は通常 self を返しますが、取り除く改行がなかった場合は nil を返します。
//emlist[例][ruby]{
buf = "string\n"
buf.chomp! # => nil
p buf # => "string"
$/ = "\n" # デフォルトと同じ
p "foo\r".chomp! # => "foo"
p "foo\r\n".chomp! # => "foo"
p......"foo\n".chomp! # => "foo"
p "foo\n\r".chomp! # => "foo\n"
buf = "string\n"
buf.chomp!(nil) # => nil
p buf # => "string\n"
p "foo\r\n\n".chomp!("") # => "foo"
p "foo\n\r\n".chomp!("") # => "foo"
p "foo\n\r\r".chomp!("") # => nil
//}
@see String#chomp
@see String#chop!......"foo\n".chomp! # => "foo"
p "foo\n\r".chomp! # => "foo\n"
buf = "string\n"
buf.chomp!(nil) # => nil
p buf # => "string\n"
p "foo\r\n\n".chomp!("") # => "foo"
p "foo\n\r\n".chomp!("") # => "foo"
p "foo\n\r\r".chomp!("") # => nil
//}
@see String#chomp
@see String#chop!
@see Stri... -
String
# chop -> String (6137.0) -
文字列の最後の文字を取り除いた新しい文字列を生成して返します。 ただし、文字列の終端が "\r\n" であればその 2 文字を取り除きます。
...終端が "\r\n" であればその 2 文字を取り除きます。
//emlist[例][ruby]{
p "string\n".chop # => "string"
p "string\r\n".chop # => "string"
p "string".chop # => "strin"
p "strin".chop # => "stri"
p "".chop # => ""
//}
@see String#chomp
@see String#chop!......ばその 2 文字を取り除きます。
//emlist[例][ruby]{
p "string\n".chop # => "string"
p "string\r\n".chop # => "string"
p "string".chop # => "strin"
p "strin".chop # => "stri"
p "".chop # => ""
//}
@see String#chomp
@see String#chop!
@see String#delete_suffix... -
String
# chop! -> self | nil (6107.0) -
文字列の最後の文字を取り除きます。 ただし、終端が "\r\n" であればその 2 文字を取り除きます。
...@return chop! は self を変更して返しますが、取り除く文字がなかった場合は nil を返します。
//emlist[例][ruby]{
str = "string\r\n"
ret = str.chop!
ret # => "string"
str # => "string"
str.chop! # => "strin"
"".chop!......# => nil
//}
@see String#chomp!
@see String#chop......# => nil
//}
@see String#chomp!
@see String#chop
@see String#delete_suffix!... -
Shell
:: CommandProcessor # glob(pattern) -> Shell :: Filter (3107.0) -
実行すると, それらを内容とする Filter オブジェクトを返します.
...実行すると, それらを内容とする Filter オブジェクトを返します.
@param pattern シェルコマンド glob に与えるパターンを指定します。
パターンの書式については、Dir.[] を参照してください。
動作例
require 'shell'
Sh......ell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|
echo(l) | tee(file + ".tee") >> "all.tee"
}
}
}
@see Dir.[]... -
Shell
:: CommandProcessor # cat(*files) -> Shell :: Filter (3007.0) -
実行すると, それらを内容とする Filter オブジェクトを返します.
...クトを返します.
@param files シェルコマンド cat に与えるファイル名を文字列で指定します。
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |... -
Shell
:: CommandProcessor # echo(*strings) -> Shell :: Filter (3007.0) -
実行すると, それらを内容とする Filter オブジェクトを返します.
...ェクトを返します.
@param strings シェルコマンド echo に与える引数を文字列で指定します。
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|... -
Shell
:: CommandProcessor # tee(file) -> Shell :: Filter (3007.0) -
実行すると, それらを内容とする Filter オブジェクトを返します.
...クトを返します.
@param file シェルコマンドtee に与えるファイル名を文字列で指定します。
動作例
require 'shell'
Shell.def_system_command("head")
sh = Shell.new
sh.transact {
glob("*.txt").to_a.each { |file|
file.chomp!
cat(file).each { |l|... -
Zlib
:: GzipReader # lineno -> Integer (3007.0) -
IO クラスの同名メソッドIO#linenoと同じです。
...メソッドIO#linenoと同じです。
但し、gzip ファイル中に
エラーがあった場合 Zlib::Error 例外や
Zlib::GzipFile::Error 例外が発生します。
gzip ファイルのフッターの処理に注意して下さい。
gzip ファイルのフッターには圧縮前データ......チェックサムが
記録されています。GzipReader オブジェクトは、次の時に展開した
データとフッターの照合を行い、エラーがあった場合は
Zlib::GzipFile::NoFooter, Zlib::GzipFile::CRCError,
Zlib::GzipFile::LengthError 例外を発生させます。
*......た時。
すなわち Zlib::GzipReader#read,
Zlib::GzipReader#gets メソッド等が nil を返す時。
* EOF まで読み込んだ後、Zlib::GzipFile#close メソッドが
呼び出された時。
* EOF まで読み込んだ後、Zlib::GzipReader#unused メソッドが
呼... -
Zlib
:: GzipReader # lineno=(num) (3007.0) -
IO クラスの同名メソッドIO#lineno=と同じです。
...ソッドIO#lineno=と同じです。
但し、gzip ファイル中に
エラーがあった場合 Zlib::Error 例外や
Zlib::GzipFile::Error 例外が発生します。
gzip ファイルのフッターの処理に注意して下さい。
gzip ファイルのフッターには圧縮前データ......チェックサムが
記録されています。GzipReader オブジェクトは、次の時に展開した
データとフッターの照合を行い、エラーがあった場合は
Zlib::GzipFile::NoFooter, Zlib::GzipFile::CRCError,
Zlib::GzipFile::LengthError 例外を発生させます。
*......ib::GzipReader#read,
Zlib::GzipReader#gets メソッド等が nil を返す時。
* EOF まで読み込んだ後、Zlib::GzipFile#close メソッドが
呼び出された時。
* EOF まで読み込んだ後、Zlib::GzipReader#unused メソッドが
呼び出された時。
@param n... -
IO
# readlines(limit , chomp: false) -> [String] (258.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
...があります。
@param rs 行の区切りを文字列で指定します。rs に nil を指定すると行区切りなしとみなします。
空文字列 "" を指定すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読......ト数
@param chomp true を指定すると各行の末尾から rs を取り除きます。
@raise IOError 自身が読み込み用にオープンされていなければ発生します。
//emlist[例][ruby]{
IO.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readli......e2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines(3) } # => ["lin", "e1,", "\n", "lin", "e2,", "\n", "lin", "e3,", "\n"]
File.open("testfile") { |f| p f.readlines(",") } # => ["line1,", "\nline2,", "\nline3,", "\n"]
//}
//emlist[例: rsを取り除く(chomp = true)][ruby]{
IO.writ... -
IO
# readlines(rs = $ / , chomp: false) -> [String] (258.0) -
データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。
...があります。
@param rs 行の区切りを文字列で指定します。rs に nil を指定すると行区切りなしとみなします。
空文字列 "" を指定すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読......ト数
@param chomp true を指定すると各行の末尾から rs を取り除きます。
@raise IOError 自身が読み込み用にオープンされていなければ発生します。
//emlist[例][ruby]{
IO.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readli......e2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines(3) } # => ["lin", "e1,", "\n", "lin", "e2,", "\n", "lin", "e3,", "\n"]
File.open("testfile") { |f| p f.readlines(",") } # => ["line1,", "\nline2,", "\nline3,", "\n"]
//}
//emlist[例: rsを取り除く(chomp = true)][ruby]{
IO.writ...