種類
- インスタンスメソッド (105)
- 特異メソッド (33)
- クラス (11)
- 文書 (7)
モジュール
-
Net
:: HTTPHeader (33)
オブジェクト
- ENV (33)
キーワード
-
NEWS for Ruby 2
. 5 . 0 (7) -
fetch
_ values (18) - key (7)
- receiver (7)
検索結果
先頭5件
-
KeyError (38022.0)
-
Hash#fetch などで key に対応する value がない場合に発生します。
...Hash#fetch などで key に対応する value がない場合に発生します。
Ruby 1.8 以前では同様の場面で IndexError が発生していました。
互換性のため、KeyError は IndexError のサブクラスになっています。... -
KeyError
# key -> object (21028.0) -
KeyError の原因となったメソッド呼び出しのキーを返します。
...
KeyError の原因となったメソッド呼び出しのキーを返します。
@raise ArgumentError キーが設定されていない時に発生します。
例:
h = Hash.new
begin
h.fetch('gumby'*20)
rescue KeyError => e
p e.message # => "key not found: \"gumbygumby... -
KeyError
# receiver -> object (21028.0) -
KeyError の原因となったメソッド呼び出しのレシーバを返します。
...
KeyError の原因となったメソッド呼び出しのレシーバを返します。
@raise ArgumentError レシーバが設定されていない時に発生します。
例:
h = Hash.new
begin
h.fetch('gumby'*20)
rescue KeyError => e
p e.message # => "key not found:... -
Hash
# fetch(key) -> object (18163.0) -
key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。
...default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。
fetchはハッシュ自身にデフォルト値が設定されていても単に無視します(挙動に変化がありません)。
@param key 探......判別できない。
p h.fetch(:one) #=> nil
p h.fetch(:two) # エラー key not found (KeyError)
p h.fetch(:two,"error") #=> "error"
p h.fetch(:two){|key|"#{key} not exist"} #=> "two not exist"
p h.fetch(:two, "error"){|key|......o not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が表示される。
h.default = "default"
p h.fetch(:two) # エラー key not found (KeyError)
//}
@see Hash#[]......wo not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が表示される。
h.default = "default"
p h.fetch(:two) # エラー key not found (KeyError)
//}
@see Hash#[]... -
Hash
# fetch(key) {|key| . . . } -> object (18163.0) -
key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。
...default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。
fetchはハッシュ自身にデフォルト値が設定されていても単に無視します(挙動に変化がありません)。
@param key 探......判別できない。
p h.fetch(:one) #=> nil
p h.fetch(:two) # エラー key not found (KeyError)
p h.fetch(:two,"error") #=> "error"
p h.fetch(:two){|key|"#{key} not exist"} #=> "two not exist"
p h.fetch(:two, "error"){|key|......o not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が表示される。
h.default = "default"
p h.fetch(:two) # エラー key not found (KeyError)
//}
@see Hash#[]......wo not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が表示される。
h.default = "default"
p h.fetch(:two) # エラー key not found (KeyError)
//}
@see Hash#[]... -
Hash
# fetch(key , default) -> object (18163.0) -
key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。
...default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。
fetchはハッシュ自身にデフォルト値が設定されていても単に無視します(挙動に変化がありません)。
@param key 探......判別できない。
p h.fetch(:one) #=> nil
p h.fetch(:two) # エラー key not found (KeyError)
p h.fetch(:two,"error") #=> "error"
p h.fetch(:two){|key|"#{key} not exist"} #=> "two not exist"
p h.fetch(:two, "error"){|key|......o not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が表示される。
h.default = "default"
p h.fetch(:two) # エラー key not found (KeyError)
//}
@see Hash#[]......wo not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が表示される。
h.default = "default"
p h.fetch(:two) # エラー key not found (KeyError)
//}
@see Hash#[]... -
Thread
# fetch(name , default = nil) {|name| . . . } -> object (18143.0) -
name に関連づけられたスレッドに固有のデータを返します。 name に対応するスレッド固有データがない時には、引数 default が 与えられていればその値を、ブロックが与えられていれば そのブロックを評価した値を返します。
...@raise KeyError 引数defaultもブロックも与えられてない時、
name に対応するスレッド固有データがないと発生します。
//emlist[例][ruby]{
th = Thread.new { Thread.current[:name] = 'A' }
th.join
th.fetch(:name) # => "A"
th.fetch(:fetch, 'B') #......=> "B"
th.fetch('name') {|name| "Thread" + name} # => "A"
th.fetch('fetch') {|name| "Thread" + name} # => "Threadfetch"
//}
@see Thread#[]... -
Net
:: HTTPHeader # fetch(key) -> String (18133.0) -
key ヘッダフィールドを返します。
...dex.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-length">
end
//}
//emlist[例......: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 ヘッダフィールドを返します。
...dex.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-length">
end
//}
//emlist[例......: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 ヘッダフィールドを返します。
...dex.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-length">
end
//}
//emlist[例......: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 } # =>... -
ENV
. fetch(key) -> String (18109.0) -
key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。そのいずれ でもなければ例外が発生します。
...to_str メソッドによる暗黙の型変換を試みます。
@param default keyに対応する環境変数の値がないときにこの値を返します。
@raise KeyError 引数defaultもブロックも与えられてない時、キーの探索に失敗すると発生します。...