別のキーワード
ライブラリ
- ビルトイン (815)
- csv (120)
-
irb
/ cmd / help (12) -
irb
/ context (24) - optparse (24)
- pathname (36)
- rake (12)
- stringio (86)
- strscan (24)
クラス
-
ARGF
. class (108) - Array (12)
- BasicObject (12)
- Binding (19)
- CSV (84)
-
CSV
:: FieldInfo (12) - Enumerator (24)
-
Enumerator
:: Yielder (6) - IO (272)
-
IRB
:: Context (24) -
IRB
:: ExtendCommand :: Help (12) - Module (36)
- OptionParser (24)
- Pathname (36)
-
Rake
:: FileList (12) -
RubyVM
:: AbstractSyntaxTree :: Node (14) -
RubyVM
:: InstructionSequence (12) - String (216)
- StringIO (86)
- StringScanner (24)
- Thread (24)
-
Thread
:: Backtrace :: Location (12) - TracePoint (12)
モジュール
- Enumerable (60)
キーワード
- [] (72)
-
add
_ trace _ func (12) -
beginning
_ of _ line? (12) - binread (12)
- bol? (12)
- chunk (12)
-
class
_ eval (12) -
const
_ source _ location (12) - convert (36)
- each (96)
-
each
_ char (24) -
each
_ codepoint (24) -
each
_ line (144) - egrep (12)
- eval (12)
- execute (12)
-
field
_ size _ limit (12) -
first
_ lineno (19) - gets (36)
-
inplace
_ mode (12) -
inplace
_ mode= (12) -
instance
_ eval (12) -
last
_ lineno (7) - lineno (36)
- lines (38)
-
module
_ eval (12) - next (12)
-
next
_ values (12) -
parse
_ csv (12) - pos (12)
- pos= (12)
- pread (8)
- readline (24)
- readlines (60)
- reopen (36)
-
set
_ trace _ func (12) - slice (72)
-
slice
_ before (24) -
source
_ location (7) - stat (12)
- sum (36)
- summarize (24)
- tell (12)
-
to
_ csv (12) -
to
_ proc (6) -
use
_ readline (12) -
use
_ readline? (12)
検索結果
先頭5件
-
CSV
:: FieldInfo # line -> Integer (18114.0) -
行番号を返します。
...行番号を返します。
//emlist[例][ruby]{
require 'csv'
csv = CSV.new("date1,date2,date3\n2018-07-09,2018-07-10\n2018-08-09,2018-08-10", headers: true)
csv.convert do |field,field_info|
p field_info.line
Date.parse(field)
end
p csv.to_a
# => 2
# => 2
# => 3
# => 3
# => [#<CSV::Row "da... -
RubyVM
:: AbstractSyntaxTree :: Node # first _ lineno -> Integer (9107.0) -
ソースコード中で、self を表すテキストが最初に現れる行番号を返します。
...ソースコード中で、self を表すテキストが最初に現れる行番号を返します。
行番号は1-originです。
//emlist[][ruby]{
node = RubyVM::AbstractSyntaxTree.parse('1 + 2')
p node.first_lineno # => 1
//}... -
RubyVM
:: AbstractSyntaxTree :: Node # last _ lineno -> Integer (9107.0) -
ソースコード中で、self を表すテキストが最後に現れる行番号を返します。
...ソースコード中で、self を表すテキストが最後に現れる行番号を返します。
行番号は1-originです。
//emlist[][ruby]{
node = RubyVM::AbstractSyntaxTree.parse('1 + 1')
p node.last_lineno # => 1
//}... -
RubyVM
:: InstructionSequence # first _ lineno -> Integer (9101.0) -
self が表す命令シーケンスの 1 行目の行番号を返します。
...の 1 行目の行番号を返します。
例1:irb で実行した場合
RubyVM::InstructionSequence.compile('num = 1 + 2').first_lineno
# => 1
例2:
# /tmp/method.rb
require "foo-library"
def foo
p :foo
end
RubyVM::InstructionSequence.of(method(:foo)).first_lineno
# => 2... -
Pathname
# each _ line(*args) {|line| . . . } -> nil (6318.0) -
IO.foreach(self.to_s, *args, &block) と同じです。
...][ruby]{
require "pathname"
IO.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line
# => #<Enumerator: IO:foreach("testfile")>
//}
//emlist[例 ブロックを指定][ruby]{
require "pathname"
IO.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line {|f|......p f }
# => "line1\n"
# => "line2,\n"
# => "line3\n"
//}
//emlist[例 limit を指定][ruby]{
require "pathname"
IO.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line(4) {|f| p f }
# => "line"
# => "1\n"
# => "line"
# => "2,\n"
# => "line"
# => "3\n"
//}
//emlist[例 sep......を指定][ruby]{
require "pathname"
IO.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line(",") {|f| p f }
# => "line1\nline2,"
# => "\nline3\n"
//}
@see IO.foreach... -
String
# lines(rs = $ / , chomp: false) {|line| . . . } -> self (6260.0) -
文字列中の各行を文字列の配列で返します。(self.each_line.to_a と同じです)
...列の配列で返します。(self.each_line.to_a と同じです)
//emlist[][ruby]{
"aa\nbb\ncc\n".lines # => ["aa\n", "bb\n", "cc\n"]
//}
行の区切りは rs に指定した文字列で、 そのデフォルト値は変数 $/ の値です。
各 line には区切りの文字列も含みます......に true を指定すると、分割した各行の末尾から rs を取り除きます。
//emlist[][ruby]{
"hello\nworld\n".lines # => ["hello\n", "world\n"]
"hello\nworld\n".lines(chomp: true) # => ["hello", "world"]
//}
@param rs 行末を示す文字列
@param chomp 分割し......省略した場合は false を指定したとみなされます。
ブロックが指定された場合は String#each_line と同じように動作します。
Ruby 2.6 までは deprecated の警告が出ますが、Ruby 2.7 で警告は削除されました。
@see String#each_line... -
String
# lines(rs = $ / ) {|line| . . . } -> self (6254.0) -
文字列中の各行を文字列の配列で返します。(self.each_line.to_a と同じです)
...列の配列で返します。(self.each_line.to_a と同じです)
//emlist[][ruby]{
"aa\nbb\ncc\n".lines # => ["aa\n", "bb\n", "cc\n"]
//}
行の区切りは rs に指定した文字列で、 そのデフォルト値は変数 $/ の値です。
各 line には区切りの文字列も含みます......(つまり空行で分割します)。
@param rs 行末を示す文字列
ブロックが指定された場合は String#each_line と同じように動作します。
Ruby 2.6 までは deprecated の警告が出ますが、Ruby 2.7 で警告は削除されました。
@see String#each_line... -
String
# each _ line(rs = $ / ) {|line| . . . } -> self (6244.0) -
文字列中の各行に対して繰り返します。 行の区切りは rs に指定した文字列で、 そのデフォルト値は変数 $/ の値です。 各 line には区切りの文字列も含みます。
...行に対して繰り返します。
行の区切りは rs に指定した文字列で、
そのデフォルト値は変数 $/ の値です。
各 line には区切りの文字列も含みます。
rs に nil を指定すると行区切りなしとみなします。
rs に空文字列 "" を指定....../emlist[例][ruby]{
"aa\nbb\ncc\n".each_line do |line|
p line
end
# => "aa\n"
# => "bb\n"
# => "cc\n"
p "aa\nbb\ncc\n".lines.to_a # => ["aa\n", "bb\n", "cc\n"]
p "aa\n".lines.to_a # => ["aa\n"]
p "".lines.to_a # => []
s = "aa\nbb\ncc\n"
p s.lines("\n").to_a......#=> ["aa\n", "bb\n", "cc\n"]
p s.lines("bb").to_a #=> ["aa\nbb", "\ncc\n"]
//}
@see String#lines... -
String
# each _ line(rs = $ / , chomp: false) {|line| . . . } -> self (6244.0) -
文字列中の各行に対して繰り返します。 行の区切りは rs に指定した文字列で、 そのデフォルト値は変数 $/ の値です。 各 line には区切りの文字列も含みます。
...行に対して繰り返します。
行の区切りは rs に指定した文字列で、
そのデフォルト値は変数 $/ の値です。
各 line には区切りの文字列も含みます。
rs に nil を指定すると行区切りなしとみなします。
rs に空文字列 "" を指定....../emlist[例][ruby]{
"aa\nbb\ncc\n".each_line do |line|
p line
end
# => "aa\n"
# => "bb\n"
# => "cc\n"
p "aa\nbb\ncc\n".lines.to_a # => ["aa\n", "bb\n", "cc\n"]
p "aa\n".lines.to_a # => ["aa\n"]
p "".lines.to_a # => []
s = "aa\nbb\ncc\n"
p s.lines("\n").to_a......#=> ["aa\n", "bb\n", "cc\n"]
p s.lines("bb").to_a #=> ["aa\nbb", "\ncc\n"]
//}
@see String#lines... -
Pathname
# each _ line(*args) -> Enumerator (6218.0) -
IO.foreach(self.to_s, *args, &block) と同じです。
...][ruby]{
require "pathname"
IO.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line
# => #<Enumerator: IO:foreach("testfile")>
//}
//emlist[例 ブロックを指定][ruby]{
require "pathname"
IO.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line {|f|......p f }
# => "line1\n"
# => "line2,\n"
# => "line3\n"
//}
//emlist[例 limit を指定][ruby]{
require "pathname"
IO.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line(4) {|f| p f }
# => "line"
# => "1\n"
# => "line"
# => "2,\n"
# => "line"
# => "3\n"
//}
//emlist[例 sep......を指定][ruby]{
require "pathname"
IO.write("testfile", "line1\nline2,\nline3\n")
Pathname("testfile").each_line(",") {|f| p f }
# => "line1\nline2,"
# => "\nline3\n"
//}
@see IO.foreach... -
IO
# readlines(limit , chomp: false) -> [String] (6173.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......=> ["line1,", "\nline2,", "\nline3,", "\n"]
//}
//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,", "\nline3,\n"]
//}
@see $/, IO#gets... -
IO
# readlines(rs = $ / , chomp: false) -> [String] (6173.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......=> ["line1,", "\nline2,", "\nline3,", "\n"]
//}
//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,", "\nline3,\n"]
//}
@see $/, IO#gets...