るりまサーチ

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

別のキーワード

  1. _builtin hash
  2. hash []
  3. matrix hash
  4. dbm to_hash
  5. _builtin to_hash

検索結果

<< 1 2 3 ... > >>

Hash#fetch(key) -> object (27151.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 (27151.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 (27151.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#[]...

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

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

...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 } # =>...

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

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

...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 (18137.0)

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

...('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...

PStore#fetch(name, default = PStore::Error) -> object (18131.0)

ルートnameに対応する値を得ます。

...]
ary = db["root"] = [1,2,3,4]
ary[0] = [1,1.5]
end

db.transaction(true) do |pstore|
pstore.fetch("root") # => [[1, 1.5], 2, 3, 4]
pstore.fetch("root", 'aaa') # => [[1, 1.5], 2, 3, 4]
pstore.fetch("not_root") # => 例外発生
end

@see Hash#fetch, PStore#[]...

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

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

...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 (18128.0)

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

...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 } # =>...

Hash#fetch_values(key, ...) -> [object] (15138.0)

引数で指定されたキーに関連づけられた値の配列を返します。

...=> "feline", "dog" => "canine", "cow" => "bovine" }

h.fetch_values("cow", "cat") # => ["bovine", "feline"]
h.fetch_values("cow", "bird") # raises KeyError
h.fetch_values("cow", "bird") { |k| k.upcase } # => ["bovine", "BIRD"]
//}

@see Hash#values_at, Hash#fetch...

絞り込み条件を変える

<< 1 2 3 ... > >>