るりまサーチ

最速Rubyリファレンスマニュアル検索!
534件ヒット [101-200件を表示] (0.020秒)
トップページ > クエリ:end[x] > クエリ:result[x]

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. io seek_end

ライブラリ

クラス

モジュール

キーワード

検索結果

<< < 1 2 3 4 ... > >>

Timeout.#timeout(sec, exception_class = nil) {|i| ... } -> object (54.0)

ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。

...x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
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])
#...
...ムアウト
#!/usr/bin/env ruby

require 'timeout'

class MYError < Exception;end
begin
Timeout.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MYError"
puts err
end


=== 注意

timeout による割り込みは Thread によって実現されてい...
...= 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 unless com.nil?
end


#止まっているか確認する。
#system("ps...

Timeout.#timeout(sec, exception_class, message) {|i| ... } -> object (54.0)

ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。

...x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
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])
#...
...ムアウト
#!/usr/bin/env ruby

require 'timeout'

class MYError < Exception;end
begin
Timeout.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MYError"
puts err
end


=== 注意

timeout による割り込みは Thread によって実現されてい...
...= 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 unless com.nil?
end


#止まっているか確認する。
#system("ps...

Enumerator::Lazy.new(obj, size=nil) {|yielder, *values| ... } -> Enumerator::Lazy (48.0)

Lazy Enumerator を作成します。Enumerator::Lazy#force メソッドなどに よって列挙が実行されたとき、objのeachメソッドが実行され、値が一つずつ ブロックに渡されます。ブロックは、yielder を使って最終的に yield される値を 指定できます。

...dule Enumerable
def filter_map(&block)
map(&block).compact
end

end


class Enumerator::Lazy
def filter_map
Lazy.new(self) do |yielder, *values|
result
= yield *values
yielder << result if result
end

end

end


1.step.lazy.filter_map{|i| i*i if i.even?}.first(5)
# =>...

coverage (42.0)

カバレッジを測定するためのライブラリです。

...測定を開始する。
(3) require や load で測定対象のファイルを実行する。
(4) Coverage.result や Coverage.peek_result で結果を確認する。

Coverage.result は、ファイル名をキーとし、カバレッジ測定結果を値とするハッシュを返します。...
...s do |x|
s += x
end


if s == 45
p :ok
else
p :ng
end

//}

以下のようにして測定を行います。

//emlist[][ruby]{
require "coverage"
Coverage.start
load "foo.rb"
p Coverage.result # => {"foo.rb"=>[1, 1, 10, nil, nil, 1, 1, nil, 0, nil]}
//}

この Coverage.result["foo.rb"] から...

CSV#force_quotes? -> bool (36.0)

出力される全てのフィールドがクオートされる場合は、真を返します。

..."row1_2"]]
result
= CSV.generate(force_quotes: false) do |csv|
rows.each { |row| csv << row }
csv.force_quotes? # => false
end

print result

# => header1,header2
# "row1_1,",row1_2
//}

//emlist[例][ruby]{
require "csv"

rows = [["header1", "header2"], ["row1_1,", "row1_2"]]
result
= CSV.gen...
...erate(force_quotes: true) do |csv|
rows.each { |row| csv << row }
csv.force_quotes? # => true
end

print result

# => true
# => "header1","header2"
# "row1_1,","row1_2"
//}

@see CSV.new...

絞り込み条件を変える

CSV#write_headers? -> bool (36.0)

ヘッダを出力先に書き込む場合は真を返します。 そうでない場合は偽を返します。

...1", "row1_2"]
result
= CSV.generate(headers: header, write_headers: false) do |csv|
csv.write_headers? # => false
csv << row
end

result
# => "row1_1,row1_2\n"

result
= CSV.generate(headers: header, write_headers: true) do |csv|
csv.write_headers? # => true
csv << row
end

result
# => "header...

Kernel.#catch {|tag| .... } -> object (36.0)

Kernel.#throwとの組み合わせで大域脱出を行います。 catch はブロックを実行します。

...@return ブロックの返り値か、対応するthrowの第二引数を返り値として返します。

//emlist[例][ruby]{
result
= catch do |tag|
for i in 1..2
for j in 1..2
for k in 1..2
throw tag, k
end

end

end

end


p result #=> 1
//}

@see Kernel.#throw...

Kernel.#catch(tag) {|tag| .... } -> object (36.0)

Kernel.#throwとの組み合わせで大域脱出を行います。 catch はブロックを実行します。

...@return ブロックの返り値か、対応するthrowの第二引数を返り値として返します。

//emlist[例][ruby]{
result
= catch do |tag|
for i in 1..2
for j in 1..2
for k in 1..2
throw tag, k
end

end

end

end


p result #=> 1
//}

@see Kernel.#throw...

Object#_dump(limit) -> String (36.0)

Marshal.#dump において出力するオブジェクトがメソッド _dump を定義している場合には、そのメソッドの結果が書き出されます。

...べきです。

//emlist[][ruby]{
class Foo
def initialize(arg)
@foo = arg
end

def _dump(limit)
Marshal.dump(@foo, limit)
end

def self._load(obj)
p obj
Foo.new(Marshal.load(obj))
end

end

foo = Foo.new(['foo', 'bar'])
p foo #=> #<Foo:0xbaf234 @foo=["f...
..."bar"]>
dms = Marshal.dump(foo)
p dms #=> "\004\bu:\bFoo\023\004\b[\a\"\bfoo\"\bbar"
result
= Marshal.load(dms) #=> "\004\b[\a\"\bfoo\"\bbar" # self._load の引数
p result #=> #<Foo:0xbaf07c @foo=["foo", "bar"]>
//}

インスタンス変数の情報は普...

Object#marshal_dump -> object (36.0)

Marshal.#dump を制御するメソッドです。

...= arg
end

def marshal_dump
@foo
end

def marshal_load(obj)
p obj
@foo = obj
end

end

foo = Foo.new(['foo', 'bar'])
p foo #=> #<Foo:0xbaf3b0 @foo=["foo", "bar"]>
dms = Marshal.dump(foo)
p dms #=> "\004\bU:\bFoo[\a\"\bfoo\"\bbar"
result
= M...
...arshal.load(dms) #=> ["foo", "bar"] # marshal_load の引数
p result #=> #<Foo:0xbaf2ac @foo=["foo", "bar"]>
//}

インスタンス変数の情報は普通マーシャルデータに含まれるので、
上例のように marshal_dump を定義する必要はありません
(た...

絞り込み条件を変える

<< < 1 2 3 4 ... > >>