るりまサーチ

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

別のキーワード

  1. _builtin fetch
  2. httpheader fetch
  3. env fetch
  4. net/http fetch
  5. array fetch

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

GDBM#fetch(key, ifnone = nil) {|key| ... } -> object (18149.0)

データベースから対応するキーを探してその要素の値を返します。

...

@raise IndexError ifnone が設定されていないときに、対応するキーが
見つからなかった場合に発生します。

require 'gdbm'

db1 = GDBM.open('aaa.gdbm', 0666, GDBM::NEWDB)
db1['a'] = 'aaa'
db1['b'] = 'bbb'

p db1.fetch('a')...
...#=> 'aaa'
p db1.fetch('z', 'zzz') #=> 'zzz'
p db1.fetch('z'){|key| [:key, key] } #=> [:key, 'z']
p db1.fetch('z', 'zzz'){|key| [:key, key] } #=> 'zzz'
p db1.fetch('z') #=> IndexError 発生

@see Hash#fetch...

DBM#fetch(key, ifnone = nil) -> String (18143.0)

データベースからキーを探して対応する要素の値を返します。

...

@raise IndexError ifnone を指定していないとき、キーが見つからなかった場合に発生します。

require 'dbm'

db1 = DBM.open('aaa.db', 0666, DBM::NEWDB)
db1[:a] = 'aaa'
db1[:b] = 'bbbbbb'
p db1.fetch('a') #=> 'aaa'
p db1.fetch('z', 'zzz...
...') #=> 'zzz'
p db1.fetch('z'){|key| [:key, key] } #=> [:key, 'z']
p db1.fetch('z') #=> IndexError 発生

@see Hash#fetch...

SDBM#fetch(key, ifnone = nil) {|key| ... } -> object (18143.0)

データベースから対応するキーを探してその要素の値を返します。

...@raise IndexError ifnone が設定されていないときに、対応するキーが
見つからなかった場合に発生します。

require 'sdbm'

db1 = SDBM.open('aaa.gdbm', 0666)
db1['a'] = 'aaa'
db1['b'] = 'bbb'
db1['c'] = 'ccc'

p db1.fetch('a')...
...#=> "aaa"
p db1.fetch('z', 'zzz') #=> "zzz"
p db1.fetch('z'){|key| [:key, key] } #=> [:key, "z"]
p db1.fetch('z', 'zzz'){|key| [:key, key] } #=> "zzz"
p db1.fetch('z') #=> IndexError 発生...

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

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

...します。

Array#[] (nth) とは nth 番目の要素が存在しない場合の振舞いが異
なります。最初の形式では、例外 IndexError が発生します。
二番目の形式では、引数 ifnone を返します。
三番目の形式では、ブロックを評価した結果を...
...e IndexError 引数 ifnone もブロックも指定しておらず、 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 (18139.0)

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

...します。

Array#[] (nth) とは nth 番目の要素が存在しない場合の振舞いが異
なります。最初の形式では、例外 IndexError が発生します。
二番目の形式では、引数 ifnone を返します。
三番目の形式では、ブロックを評価した結果を...
...e IndexError 引数 ifnone もブロックも指定しておらず、 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 (18139.0)

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

...します。

Array#[] (nth) とは nth 番目の要素が存在しない場合の振舞いが異
なります。最初の形式では、例外 IndexError が発生します。
二番目の形式では、引数 ifnone を返します。
三番目の形式では、ブロックを評価した結果を...
...e IndexError 引数 ifnone もブロックも指定しておらず、 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
//}...

Net::HTTPHeader#fetch(key) -> String (18133.0)

key ヘッダフィールドを返します。

...ール名を文字列で与えます。
@param default 該当するキーが登録されていない時の返り値を指定します。
@raise IndexError 引数defaultもブロックも与えられてない時、キーの探索に 失敗すると発生します。

//emlist[例 key のみ指定。k...
...http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.fetch("user-agent") # => "Ruby"
//}

//emlist[例 key のみ指定。key が存在しない][ruby]{
require 'net/http'

begin
req.fetch("content-length")
rescue => e
e # => #<KeyError: key not found: "content-lengt...
...:HTTP::Get.new(uri.request_uri)
req.fetch("content-length", "default") # => "default"
//}

//emlist[例 key とブロックを指定][ruby]{
require 'net/http'

uri = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.fetch("content-length") { |e| 99 } # =>...

Net::HTTPHeader#fetch(key) {|hash| .... } -> String (18133.0)

key ヘッダフィールドを返します。

...ール名を文字列で与えます。
@param default 該当するキーが登録されていない時の返り値を指定します。
@raise IndexError 引数defaultもブロックも与えられてない時、キーの探索に 失敗すると発生します。

//emlist[例 key のみ指定。k...
...http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.fetch("user-agent") # => "Ruby"
//}

//emlist[例 key のみ指定。key が存在しない][ruby]{
require 'net/http'

begin
req.fetch("content-length")
rescue => e
e # => #<KeyError: key not found: "content-lengt...
...:HTTP::Get.new(uri.request_uri)
req.fetch("content-length", "default") # => "default"
//}

//emlist[例 key とブロックを指定][ruby]{
require 'net/http'

uri = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.fetch("content-length") { |e| 99 } # =>...

Net::HTTPHeader#fetch(key, default) -> String (18133.0)

key ヘッダフィールドを返します。

...ール名を文字列で与えます。
@param default 該当するキーが登録されていない時の返り値を指定します。
@raise IndexError 引数defaultもブロックも与えられてない時、キーの探索に 失敗すると発生します。

//emlist[例 key のみ指定。k...
...http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.fetch("user-agent") # => "Ruby"
//}

//emlist[例 key のみ指定。key が存在しない][ruby]{
require 'net/http'

begin
req.fetch("content-length")
rescue => e
e # => #<KeyError: key not found: "content-lengt...
...:HTTP::Get.new(uri.request_uri)
req.fetch("content-length", "default") # => "default"
//}

//emlist[例 key とブロックを指定][ruby]{
require 'net/http'

uri = URI.parse('http://www.example.com/index.html')
req = Net::HTTP::Get.new(uri.request_uri)
req.fetch("content-length") { |e| 99 } # =>...
<< 1 2 > >>