別のキーワード
ライブラリ
クラス
- Addrinfo (24)
- CSV (156)
-
CSV
:: Table (84) - Dir (12)
- ERB (36)
- Exception (12)
- IO (12)
-
JSON
:: Parser (24) -
Net
:: HTTPGenericRequest (24) -
Net
:: HTTPResponse (48) - Object (30)
- Pathname (12)
- Socket (12)
- StringIO (84)
-
Thread
:: Queue (56) -
Thread
:: SizedQueue (38)
キーワード
-
backtrace
_ locations (12) - binread (12)
- body (12)
-
body
_ stream (12) -
body
_ stream= (12) - clear (2)
- closed? (12)
- connect (12)
-
connect
_ from (24) - convert (36)
-
def
_ class (12) - deq (24)
- empty? (14)
- entity (12)
- fdatasync (12)
-
field
_ size _ limit (12) - filename (12)
- filename= (12)
- gets (12)
-
header
_ converters (12) - headers (12)
- inspect (12)
- length (14)
- max= (2)
-
num
_ waiting (12) - parse (12)
- pop (24)
- push (12)
- puts (12)
-
read
_ body (24) - readbyte (12)
- readchar (12)
- readline (24)
- readlines (24)
- reopen (24)
-
row
_ sep (12) - shift (36)
- size (14)
- source (12)
- then (14)
-
to
_ csv (12) -
to
_ s (12) -
yield
_ self (16)
検索結果
先頭5件
-
CSV
# read -> [Array] | CSV :: Table (18250.0) -
残りの行を読み込んで配列の配列を返します。 self の生成時に headers オプションに偽でない値が指定されていた場合は CSV::Table オブジェクトを返します。
...が指定されていた場合は CSV::Table オブジェクトを返します。
データソースは読み込み用にオープンされている必要があります。
//emlist[例 headers: false][ruby]{
require "csv"
csv = CSV.new(DATA.read)
csv.read
# => [["header1", "header2"], ["row1_1",......"row1_2"], ["row2_1", "row2_2"]]
__END__
header1,header2
row1_1,row1_2
row2_1,row2_2
//}
//emlist[例 headers: true][ruby]{
require "csv"
csv = CSV.new(DATA.read, headers: true)
csv.read
# => #<CSV::Table mode:col_or_row row_count:3>
__END__
header1,header2
row1_1,row1_2
row2_1,row2_2
//}... -
Dir
# read -> String | nil (18244.0) -
ディレクトリストリームから次の要素を読み出して返します。最後の要素 まで読み出していれば nil を返します。
...emlist[例][ruby]{
require 'tmpdir'
Dir.mktmpdir do |tmpdir|
File.open("#{tmpdir}/test1.txt", "w") { |f| f.puts("test1") }
File.open("#{tmpdir}/test2.txt", "w") { |f| f.puts("test2") }
Dir.open(tmpdir) do |d|
p d.read # => "."
p d.read # => ".."
p d.read # => "test1.txt"......p d.read # => "test2.txt"
p d.read # => nil
end
end
//}... -
StringIO
# readbyte -> Integer (12313.0) -
自身から 1 文字読み込んで、その文字に対応する整数を返します。
...対応する整数を返します。
文字列の終端に到達した時には例外 EOFError を発生させます。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge")
a.readbyte #=> 104
//}
@raise EOFError 文字列の終端に到達した時に発生します。... -
Thread
:: Queue # length -> Integer (12113.0) -
キューの長さを返します。
...キューの長さを返します。
//emlist[例][ruby]{
require 'thread'
q = Queue.new
[:resource1, :resource2, :resource3, nil].each { |r| q.push(r) }
q.length # => 4
//}... -
Exception
# backtrace _ locations -> [Thread :: Backtrace :: Location] (9313.0) -
バックトレース情報を返します。Exception#backtraceに似ていますが、 Thread::Backtrace::Location の配列を返す点が異なります。
...ption#backtraceに似ていますが、
Thread::Backtrace::Location の配列を返す点が異なります。
現状では Exception#set_backtrace によって戻り値が変化する事はあり
ません。
//emlist[例: test.rb][ruby]{
require "date"
def check_long_month(month)
return if Dat......month, -1).day == 31
raise "#{month} is not long month"
end
def get_exception
return begin
yield
rescue => e
e
end
end
e = get_exception { check_long_month(2) }
p e.backtrace_locations
# => ["test.rb:4:in `check_long_month'", "test.rb:15:in `block in <main>'", "test.rb:9:in `get_ex......ception'", "test.rb:15:in `<main>'"]
//}
@see Exception#backtrace... -
Net
:: HTTPResponse # read _ body {|str| . . . . } -> () (9245.0) -
ブロックを与えなかった場合にはエンティティボディを 文字列で返します。 ブロックを与えた場合には エンティティボディを少しずつ取得して順次ブロックに 文字列で与えます。
...t[例1 ブロックを与えずに一度に結果取得][ruby]{
require 'net/http'
uri = "http://www.example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.read_body[0..10] # => "<!doctype h"
//}
//emlist[例2 ブロックを与えて大きいファイルを取得][ruby......{
require 'net/http'
uri = URI.parse('http://www.example.com/path/to/big.file')
Net::HTTP.start(uri.host, uri.port) do |http|
File.open("/path/to/big.file", "w") do |f|
# Net::HTTP#request_get と Net::HTTPResponse#read_body で少しずつ読み書き。メモリ消費が少ない。
htt......p.request_get(uri.path) do |response|
response.read_body do |s|
f.write(s)
end
end
end
end
//}
一度ブロックを与えずにこのメソッドを呼んだ場合には、
次からはすでに読みだしたボディを文字列として
返します。また一度ブ... -
Net
:: HTTPResponse # read _ body(dest=nil) -> String|nil (9245.0) -
ブロックを与えなかった場合にはエンティティボディを 文字列で返します。 ブロックを与えた場合には エンティティボディを少しずつ取得して順次ブロックに 文字列で与えます。
...t[例1 ブロックを与えずに一度に結果取得][ruby]{
require 'net/http'
uri = "http://www.example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.read_body[0..10] # => "<!doctype h"
//}
//emlist[例2 ブロックを与えて大きいファイルを取得][ruby......{
require 'net/http'
uri = URI.parse('http://www.example.com/path/to/big.file')
Net::HTTP.start(uri.host, uri.port) do |http|
File.open("/path/to/big.file", "w") do |f|
# Net::HTTP#request_get と Net::HTTPResponse#read_body で少しずつ読み書き。メモリ消費が少ない。
htt......p.request_get(uri.path) do |response|
response.read_body do |s|
f.write(s)
end
end
end
end
//}
一度ブロックを与えずにこのメソッドを呼んだ場合には、
次からはすでに読みだしたボディを文字列として
返します。また一度ブ... -
Pathname
# binread(*args) -> String | nil (9213.0) -
IO.binread(self.to_s, *args)と同じです。
....binread(self.to_s, *args)と同じです。
//emlist[例][ruby]{
require "pathname"
pathname = Pathname("testfile")
pathname.binread # => "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
pathname.binread(20) # => "This is line one\nThi"
pathname.binread(20,......10) # => "ne one\nThis is line "
//}
@see IO.binread... -
StringIO
# readchar -> String (9213.0) -
自身から 1 文字読み込んで、その文字に対応する String を返します。
...ら 1 文字読み込んで、その文字に対応する String を返します。
文字列の終端に到達した時には例外 EOFError を発生させます。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge")
a.readchar #=> "h"
//}
@raise EOFError EOFに達し... -
StringIO
# readline(rs = $ / ) -> String (9213.0) -
自身から 1 行読み込んで、その文字列を返します。
...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 が発生する...