るりまサーチ

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

別のキーワード

  1. _builtin begin
  2. range begin
  3. matchdata begin
  4. arithmeticsequence begin
  5. begin _builtin

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 > >>

StopIteration#result -> object (18113.0)

この例外オブジェクトを発生させる原因となったメソッド等の返り値を返します。

...ect = Object.new
def object.each
yield :yield1
yield :yield2
:each_returned
end

enumerator = object.to_enum

p enumerator.next #=> :yield1
p enumerator.next #=> :yield2

begin

enumerator.next
rescue StopIteration => error
p error.result #=> :each_returned
end...

NEWS for Ruby 2.5.0 (36.0)

NEWS for Ruby 2.5.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...ました 11952
* Process.last_status を追加。$? と同じです 14043

* Range
* Range.new no longer hides exceptions when comparing begin and
end with #<=> and raise a "bad value for range" ArgumentError
but instead lets the exception from the #<=> call go through....
...hods: true)
//}
* Rubyで書かれたファイルをいくつか読み込んでから、Coverage.result を使って結果を取得することができます。
//emlist[][ruby]{
Coverage.result
#=> { "/path/to/file.rb"=>
# { :lines => [1, 2, 0, nil, ...],
# :branches =>
# { [...
...また Coverage.result も旧フォーマットを返します。
//emlist[][ruby]{
Coverage.result
#=> { "/path/to/file.rb"=> [1, 2, 0, nil, ...] }
//}

* drb
* ACL::ACLEntry.new は IPAddr::InvalidPrefixError を抑制しなくなりました

* erb
* ERB#result_with_hash を追加...

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

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

...alc_pi(min)
loop do
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...
...pi = 3.141443

例 独自の例外を発生させるタイムアウト
#!/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 によ...
...id
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 au")...

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

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

...alc_pi(min)
loop do
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...
...pi = 3.141443

例 独自の例外を発生させるタイムアウト
#!/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 によ...
...id
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 au")...

String#[](substr) -> String | nil (19.0)

self が substr を含む場合、一致した文字列を新しく作って返します。 substr を含まなければ nil を返します。

...た文字列を新しく作って返します。
substr を含まなければ nil を返します。

@param substr 取得したい文字列のパターン。文字列

//emlist[例][ruby]{
substr = "bar"
result
= "foobar"[substr]
p result # => "bar"
p substr.equal?(result) # => false
//}...

絞り込み条件を変える

String#slice(substr) -> String | nil (19.0)

self が substr を含む場合、一致した文字列を新しく作って返します。 substr を含まなければ nil を返します。

...た文字列を新しく作って返します。
substr を含まなければ nil を返します。

@param substr 取得したい文字列のパターン。文字列

//emlist[例][ruby]{
substr = "bar"
result
= "foobar"[substr]
p result # => "bar"
p substr.equal?(result) # => false
//}...

Array#fetch(nth) -> object (18.0)

nth 番目の要素を返します。

...しなかった場合に発生します。

//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin

p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end

p a.fetch(10, 999) #=> 999

result
= a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #=> 999
//}...

Array#fetch(nth) {|nth| ... } -> object (18.0)

nth 番目の要素を返します。

...しなかった場合に発生します。

//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin

p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end

p a.fetch(10, 999) #=> 999

result
= a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #=> 999
//}...

Array#fetch(nth, ifnone) -> object (18.0)

nth 番目の要素を返します。

...しなかった場合に発生します。

//emlist[例][ruby]{
a = [1, 2, 3, 4, 5]
begin

p a.fetch(10)
rescue IndexError => err
puts err #=> index 10 out of array
end

p a.fetch(10, 999) #=> 999

result
= a.fetch(10){|nth|
print "#{nth} はありません。\n"
999
}
p result #=> 999
//}...
<< 1 2 3 > >>