るりまサーチ

最速Rubyリファレンスマニュアル検索!
62件ヒット [1-62件を表示] (0.070秒)

別のキーワード

  1. uri default_port
  2. _builtin default
  3. generic default_port
  4. socket ai_default
  5. socket ip_default_multicast_ttl

ライブラリ

クラス

検索結果

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

PStore#fetch(name, default = PStore::Error) -> object (18126.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#[]...

絞り込み条件を変える

tsort (12.0)

tsort はトポロジカルソートと強連結成分に関するモジュールを提供します。

...=== Example

//emlist[][ruby]{
require 'tsort'

class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch
(node).each(&block)
end
end

{1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort
#=> [3, 2, 1, 4]

{1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}.strongly_connected_co...
...似たツールは以下のように実装できます。

//emlist[][ruby]{
require 'tsort'

class Make
def initialize
@dep = {}
@dep.default = []
end

def rule(outputs, inputs=[], &block)
triple = [outputs, inputs, block]
outputs.each {|f| @dep[f] = [triple]}
@dep[triple]...