249件ヒット
[201-249件を表示]
(0.126秒)
別のキーワード
検索結果
先頭5件
-
Kernel
. # exec(env , command , options={}) -> () (23.0) -
引数で指定されたコマンドを実行します。
...EXXX 起動に失敗し、ruby インタプリタに制御が戻った場合に発生します。
//emlist[例][ruby]{
# a.rb
puts '実行前'
exec 'echo "実行中"'
puts '実行後'
//}
上記のスクリプトを実行すると以下のようになります。
$ ruby a.rb
実行前
実... -
Readline
. # readline(prompt = "" , add _ hist = false) -> String | nil (19.0) -
prompt を出力し、ユーザからのキー入力を待ちます。 エンターキーの押下などでユーザが文字列を入力し終えると、 入力した文字列を返します。 このとき、add_hist が true であれば、入力した文字列を入力履歴に追加します。 何も入力していない状態で EOF(UNIX では ^D) を入力するなどで、 ユーザからの入力がない場合は nil を返します。
...したと想定します。)
> cd
p input # => "cd"
本メソッドには注意事項があります。
入力待ちの状態で ^C すると ruby インタプリタが終了し、端末状態を復帰しません。
これを回避するための例を2つ挙げます。
例: ^CによるInte......dline.readline
p buf
end
rescue Interrupt
system("stty", stty_save)
exit
end
例: INTシグナルを捕捉して、端末状態を復帰する。
require 'readline'
stty_save = `stty -g`.chomp
trap("INT") { system "stty", stty_save; exit }
while buf = Readline.rea... -
Benchmark
. # bmbm(width = 0) {|job| . . . } -> [Benchmark :: Tms] (13.0) -
Benchmark::Job オブジェクトを生成して、それを引数として与えられたブロックを 実行します。
...用しても、GC などの影響を分離する
ことは保証されません。
@param width ラベルの幅を指定します。
//emlist[][ruby]{
require 'benchmark'
array = (1..1000000).map { rand }
Benchmark.bmbm do |x|
x.report("sort!") { array.dup.sort! }
x.report("sort") { array.d......11.938000 ( 12.756000)
# sort 13.048000 0.020000 13.068000 ( 13.857000)
# ------------------------------- total: 25.006000sec
#
# user system total real
# sort! 12.959000 0.010000 12.969000 ( 13.793000)
# sort 12.007000 0.000000 12.007000 ( 12.791000)
//}... -
Benchmark
. # measure(label = "") { . . . } -> Benchmark :: Tms (13.0) -
与えられたブロックを実行して、経過した時間を Process.#times で計り、 Benchmark::Tms オブジェクトを生成して返します。
...は to_s が定義されているので、
基本的には以下のように使います。
//emlist[][ruby]{
require 'benchmark'
puts Benchmark::CAPTION
puts Benchmark.measure { "a"*1_000_000 }
#=>
#
# user system total real
# 1.166667 0.050000 1.216667 ( 0.571355)
//}... -
FileUtils
. # uptodate?(newer , older _ list , options = nil) -> bool (13.0) -
newer が、older_list に含まれるすべてのファイルより新しいとき真。 存在しないファイルは無限に古いとみなされます。
...@param options どのようなオプションも指定することはできません。
@raise ArgumentError options にオプションを指定した場合に発生します。
//emlist[][ruby]{
require 'fileutils'
FileUtils.uptodate?('hello.o', ['hello.c', 'hello.h']) or system('make')
//}...