種類
- インスタンスメソッド (304)
- 特異メソッド (48)
- モジュール関数 (11)
クラス
-
ARGF
. class (24) - IO (208)
- String (90)
モジュール
- Enumerable (22)
- Kernel (11)
- Warning (8)
検索結果
先頭5件
-
String
# chomp(rs = $ / ) -> String (26175.0) -
self の末尾から rs で指定する改行コードを取り除いた文字列を生成して返します。 ただし、rs が "\n" ($/ のデフォルト値) のときは、 実行環境によらず "\r", "\r\n", "\n" のすべてを改行コードとみなして取り除きます。
...o\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 "string\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......) # => "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... -
Kernel
. # chomp(rs = $ / ) -> String (26167.0) -
$_.chomp とほぼ同じですが、置換が発生したときは、$_の内容を置き換える点が異なります。 コマンドラインオプションで -p または -n を指定した時のみ定義されます。
...$_.chomp とほぼ同じですが、置換が発生したときは、$_の内容を置き換える点が異なります。
コマンドラインオプションで -p または -n を指定した時のみ定義されます。
暗号的になりすぎるきらいがあるため、このメソッド......の使用は推奨されていません。
今後はより明示的な $_.chomp を使ってください。
$_.chomp とこのメソッド chomp は以下の点で違いがあります。
* chomp は $_ の値をコピーして、コピーの方を更新し、
$_ に再代入します。
@par......//emlist[例: ruby -n で "test" を入力][ruby]{
$_ # => "test\n"
chomp # => "test"
//}
//emlist[例: ruby -n で "test," を入力し、 rs に "," を指定][ruby]{
$_ # => "test\n"
chomp # => "test,"
chomp(",") # => "test"
//}
@see String#chomp,$_,$/... -
String
# chomp!(rs = $ / ) -> self | nil (14169.0) -
self の末尾から rs で指定する改行コードを取り除きます。 ただし rs が "\n" ($/ のデフォルト値) のときは、 実行環境によらず "\r", "\r\n", "\n" のすべてを改行コードとみなして取り除きます。
...@return 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"
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!
@s... -
IO
# each(limit , chomp: false) -> Enumerator (8132.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。
@raise IOError 自身が読み込み用にオ......This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: chomp = true][ruby]{
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"
# "... -
IO
# each(limit , chomp: false) {|line| . . . } -> self (8132.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。
@raise IOError 自身が読み込み用にオ......This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: chomp = true][ruby]{
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"
# "... -
IO
# each(rs = $ / , chomp: false) -> Enumerator (8132.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。
@raise IOError 自身が読み込み用にオ......This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: chomp = true][ruby]{
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"
# "... -
IO
# each(rs = $ / , chomp: false) {|line| . . . } -> self (8132.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。
@raise IOError 自身が読み込み用にオ......This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: chomp = true][ruby]{
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"
# "... -
IO
# each(rs , limit , chomp: false) -> Enumerator (8132.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。
@raise IOError 自身が読み込み用にオ......This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: chomp = true][ruby]{
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"
# "... -
IO
# each(rs , limit , chomp: false) {|line| . . . } -> self (8132.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。
@raise IOError 自身が読み込み用にオ......This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: chomp = true][ruby]{
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"
# "... -
IO
# each _ line(limit , chomp: false) -> Enumerator (8132.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。
@raise IOError 自身が読み込み用にオ......This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: chomp = true][ruby]{
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"
# "... -
IO
# each _ line(limit , chomp: false) {|line| . . . } -> self (8132.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。
@raise IOError 自身が読み込み用にオ......This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: chomp = true][ruby]{
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"
# "... -
IO
# each _ line(rs = $ / , chomp: false) -> Enumerator (8132.0) -
IO の現在位置から 1 行ずつ文字列として読み込み、それを引数として 与えられたブロックを実行します。
...すると連続する改行を行の区切りとみなします(パラグラフモード)。
@param limit 最大の読み込みバイト数
@param chomp true を指定すると各行の末尾から "\n", "\r", または "\r\n" を取り除きます。
@raise IOError 自身が読み込み用にオ......This is li"
# "3: ne three,"
# "3: And so on."
# "4: .."
//}
//emlist[例: chomp = true][ruby]{
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"
# "...