るりまサーチ

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

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method new
  4. irb/input-method gets
  5. matrix -

検索結果

<< 1 2 3 ... > >>

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

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

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

たとえばキー 'content-length' に対しては '2048'
のような文字列が得られます。キーが存在しなければ nil を返します。

該当するキーが登録されてい
ない時には、引数 default が与えられてい...
...存在する][ruby]{
require 'net/http'

uri = URI.parse('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")
resc...
..."content-length">
end
//}

//emlist[例 key , default を指定][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", "default") # => "default"
//}

//emlist[例 key とブロックを指定][ruby]{
requ...

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

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

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

たとえばキー 'content-length' に対しては '2048'
のような文字列が得られます。キーが存在しなければ nil を返します。

該当するキーが登録されてい
ない時には、引数 default が与えられてい...
...存在する][ruby]{
require 'net/http'

uri = URI.parse('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")
resc...
..."content-length">
end
//}

//emlist[例 key , default を指定][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", "default") # => "default"
//}

//emlist[例 key とブロックを指定][ruby]{
requ...

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

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

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

たとえばキー 'content-length' に対しては '2048'
のような文字列が得られます。キーが存在しなければ nil を返します。

該当するキーが登録されてい
ない時には、引数 default が与えられてい...
...存在する][ruby]{
require 'net/http'

uri = URI.parse('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")
resc...
..."content-length">
end
//}

//emlist[例 key , default を指定][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", "default") # => "default"
//}

//emlist[例 key とブロックを指定][ruby]{
requ...

Hash#fetch(key) -> object (18251.0)

key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。

...default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。

fetch
はハッシュ自身にデフォルト値が設定されていても単に無視します(挙動に変化がありません)。

@param key 探...
...//emlist[例][ruby]{
h = {one: nil}
p h[:one],h[:two] #=> nil,nil これではキーが存在するのか判別できない。
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| #=> "two not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が...

Hash#fetch(key) {|key| ... } -> object (18251.0)

key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。

...default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。

fetch
はハッシュ自身にデフォルト値が設定されていても単に無視します(挙動に変化がありません)。

@param key 探...
...//emlist[例][ruby]{
h = {one: nil}
p h[:one],h[:two] #=> nil,nil これではキーが存在するのか判別できない。
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| #=> "two not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が...

絞り込み条件を変える

Hash#fetch(key, default) -> object (18251.0)

key に関連づけられた値を返します。該当するキーが登録されてい ない時には、引数 default が与えられていればその値を、ブロッ クが与えられていればそのブロックを評価した値を返します。

...default が与えられていればその値を、ブロッ
クが与えられていればそのブロックを評価した値を返します。

fetch
はハッシュ自身にデフォルト値が設定されていても単に無視します(挙動に変化がありません)。

@param key 探...
...//emlist[例][ruby]{
h = {one: nil}
p h[:one],h[:two] #=> nil,nil これではキーが存在するのか判別できない。
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| #=> "two not exist"
"#{key} not exist" # warning: block supersedes default value argument
} # 警告が...

Thread#fetch(name, default = nil) {|name| ... } -> object (18243.0)

name に関連づけられたスレッドに固有のデータを返します。 name に対応するスレッド固有データがない時には、引数 default が 与えられていればその値を、ブロックが与えられていれば そのブロックを評価した値を返します。

...と発生します。

//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#[]...

Array#fetch(nth) -> object (18227.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 #...

Array#fetch(nth) {|nth| ... } -> object (18227.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 #...

Array#fetch(nth, ifnone) -> object (18227.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 #...

絞り込み条件を変える

<< 1 2 3 ... > >>