種類
- インスタンスメソッド (132)
- モジュール関数 (21)
- クラス (12)
- 文書 (12)
- モジュール (12)
クラス
-
Net
:: SMTP (24) -
Zlib
:: GzipReader (84) -
Zlib
:: GzipWriter (12)
モジュール
-
OpenSSL
:: Buffering (12) - Timeout (21)
検索結果
先頭5件
-
OpenSSL
:: Buffering # printf(format , *args) -> nil (21113.0) -
format に従い引数 args を文字列に変換して 出力します。
...format に従い引数 args を文字列に変換して
出力します。
IO#printf と同様です。
@param format 出力フォーマット文字列
@param arg 出力するオブジェクト
@see Kernel.#printf... -
Zlib
:: GzipWriter # printf(format , *args) -> nil (18147.0) -
C 言語の printf と同じように、format に従い引数 を文字列に変換して、自身に出力します。
...C 言語の printf と同じように、format に従い引数
を文字列に変換して、自身に出力します。
@param format フォーマット文字列を指定します。print_format を参照してください。
@param args フォーマットされるオブジェクトを指定し......。
require 'zlib'
filename='hoge1.gz'
fw = File.open(filename, "w")
Zlib::GzipWriter.wrap(fw, Zlib::BEST_COMPRESSION){|gz|
gz.printf("\n%9s", "bar")
}
fr = File.open(filename)
Zlib::GzipReader.wrap(fr){|gz|
puts gz.read
}
#=> bar
@see IO#printf, Kernel.#printf... -
Net
:: SMTP # open _ message _ stream(from _ addr , *to _ addrs) {|f| . . . . } -> () (6113.0) -
メール書き込みの準備をし、書き込み先のストリームオブジェクトを ブロックに渡します。ブロック終了後、書きこんだ結果が 送られます。
...以下のメソッドを持っています。
* puts(str = '') strを出力して CR LFを出力
* print(str) strを出力
* printf(fmt, *args) sprintf(fmt,*args) を出力
* write(str):: str を出力して書き込んだバイト数を返す
* <<(str):: str を......は送信先メールアドレスを文字列で渡します。
require 'net/smtp'
Net::SMTP.start('smtp.example.com', 25) {|smtp|
smtp.open_message_stream('from@example.com', 'to@example.net') {|f|
f.puts 'From: from@example.com'
f.puts 'To: to@example.net'
f.puts 'Subje... -
Net
:: SMTP # ready(from _ addr , *to _ addrs) {|f| . . . . } -> () (3013.0) -
メール書き込みの準備をし、書き込み先のストリームオブジェクトを ブロックに渡します。ブロック終了後、書きこんだ結果が 送られます。
...以下のメソッドを持っています。
* puts(str = '') strを出力して CR LFを出力
* print(str) strを出力
* printf(fmt, *args) sprintf(fmt,*args) を出力
* write(str):: str を出力して書き込んだバイト数を返す
* <<(str):: str を......は送信先メールアドレスを文字列で渡します。
require 'net/smtp'
Net::SMTP.start('smtp.example.com', 25) {|smtp|
smtp.open_message_stream('from@example.com', 'to@example.net') {|f|
f.puts 'From: from@example.com'
f.puts 'To: to@example.net'
f.puts 'Subje... -
ruby 1
. 6 feature (54.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...1.6.7 (2002-07-30) [i586-linux]
: 2002-06-03 sprintf()
"%d" で引数を整数にするときに、((<組み込み関数/Integer>)) と同じ規則を
使用するようになりました。
p sprintf("%d", nil)
=> -:1:in `sprintf': no implicit conversion from nil (TypeError)......dev:17155>))
open("|-","r+") {|f|
if f
f.dup.close_write
else
sleep 1
end
}
=> ruby 1.6.7 (2002-03-01) [i586-linux]
-:3:in `close_write': closing non-duplex IO for writing (IOError)
from -:3
from -:1:in `open'......ルシステムでこ
のような場合があります)が File#read などで読めないバグが修正されまし
た。
p File.open("/proc/#$$/cmdline").read
=> ruby 1.6.7 (2002-03-01) [i586-linux]
""
=> ruby 1.6.7 (2002-03-29) [i586-linux]... -
TCPServer (24.0)
-
TCP/IP ストリーム型接続のサーバ側のソケットのクラスです。
...できます。
例えば echo サーバは以下のようになります。
require "socket"
gs = TCPServer.open(0)
socks = [gs]
addr = gs.addr
addr.shift
printf("server is on %s\n", addr.join(":"))
while true
nsock = select(socks)
next if nsock == nil
for s in nso......end
end
end
end
Thread を使えばもっと短くなります。
require "socket"
gs = TCPServer.open(0)
addr = gs.addr
addr.shift
printf("server is on %s\n", addr.join(":"))
while true
Thread.start(gs.accept) do |s| # save to dynamic variable... -
Timeout
. # timeout(sec , exception _ class = nil) {|i| . . . } -> object (24.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...end
end
t = 5
min = [ 0, 0]
begin
Timeout.timeout(t){
calc_pi(min)
}
rescue Timeout::Error
puts "timeout"
end
printf "%d: pi = %f\n", min[0] + min[1], min[0]*4.0/(min[0]+min[1])
#例
#=> 417519: pi = 3.141443
例 独自の例外を発生させるタイム......イムアウトさせる事はできないので、IO.popen、Kernel.#openを使用するなどの工夫が必要です。
例 外部コマンドのタイムアウト
require 'timeout'
# テスト用のシェルをつくる。
File.open("loop.sh", "w"){|fp|
fp.print <<SHELL_EOT
#!/bin/......# system("./loop.sh")
com = IO.popen("./loop.sh")
pid = com.pid
while line = com.gets
print line
end
}
rescue Timeout::Error => err
puts "timeout: shell execution."
Process.kill('SIGINT', pid)
printf "[result]\t%s", com.read
com.close unle... -
Timeout
. # timeout(sec , exception _ class , message) {|i| . . . } -> object (24.0) -
ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。
...end
end
t = 5
min = [ 0, 0]
begin
Timeout.timeout(t){
calc_pi(min)
}
rescue Timeout::Error
puts "timeout"
end
printf "%d: pi = %f\n", min[0] + min[1], min[0]*4.0/(min[0]+min[1])
#例
#=> 417519: pi = 3.141443
例 独自の例外を発生させるタイム......イムアウトさせる事はできないので、IO.popen、Kernel.#openを使用するなどの工夫が必要です。
例 外部コマンドのタイムアウト
require 'timeout'
# テスト用のシェルをつくる。
File.open("loop.sh", "w"){|fp|
fp.print <<SHELL_EOT
#!/bin/......# system("./loop.sh")
com = IO.popen("./loop.sh")
pid = com.pid
while line = com.gets
print line
end
}
rescue Timeout::Error => err
puts "timeout: shell execution."
Process.kill('SIGINT', pid)
printf "[result]\t%s", com.read
com.close unle... -
Zlib
:: GzipReader # each _ byte -> Enumerator (18.0) -
IO クラスの同名メソッドIO#each_byteと同じです。
...=begin
# hoge.gz がない場合は下記で作成できる。
Zlib::GzipWriter.open('hoge.gz') { |gz|
gz.puts 'hoge'
}
=end
Zlib::GzipReader.open('hoge.gz') { |gz|
gz.each_byte { |b|
printf "%d -> %c\n", b, b
}
}
#=> 104 -> h
#=> 111 -> o
#=> 103 -> g
#=> 101...