種類
- インスタンスメソッド (43)
- 特異メソッド (22)
- 文書 (11)
- ライブラリ (11)
モジュール
- TSort (21)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) -
each
_ strongly _ connected _ component _ from (21) - new (22)
- tsort (11)
検索結果
先頭5件
-
Hash
# [](key) -> object | nil (39172.0) -
key に関連づけられた値を返します。
...る必要が
ある場合は Hash#fetch または Hash#key? を使ってください。
@param key 探索するキーを指定します。
//emlist[例][ruby]{
h = {:ab => "some" , :cd => "all"}
p h[:ab] #=> "some"
p h[:ef] #=> nil
h1 = Hash.new("default value")
p h1[:non]......#=> "default value"
h2 = Hash.new {|*arg| arg}
p h2[:non] #=> [{}, :non]
//}
@see Hash.new, Hash#fetch,Hash#values_at,Hash#key?, Hash#default, Hash#default_proc... -
Hash
. new {|hash , key| . . . } -> Hash (21297.0) -
空の新しいハッシュを生成します。ブロックの評価結果がデフォルト値になりま す。設定したデフォルト値はHash#default_procで参照できます。
...空の新しいハッシュを生成します。ブロックの評価結果がデフォルト値になりま
す。設定したデフォルト値はHash#default_procで参照できます。
値が設定されていないハッシュ要素を参照するとその都度ブロックを
実行し、そ......ォルト値は全部同一のオブジェクトなので、
# 破壊的変更によって他のキーに対応する値も変更されます。
h = Hash.new("foo")
p h[1] #=> "foo"
p h[1].object_id #=> 6127170
p h[1] << "bar" #=> "foobar"
p h[1] #=>......まだ無いキーが呼び出される度に
# ブロックを評価するので、全て別のオブジェクトになります。
h = Hash.new {|hash, key| hash[key] = "foo"}
p h[1] #=> "foo"
p h[1].object_id #=> 6126900
p h[1] << "bar" #=> "foobar"
p h[1]... -
Hash
. new(ifnone = nil) -> Hash (21162.0) -
空の新しいハッシュを生成します。ifnone はキーに対 応する値が存在しない時のデフォルト値です。設定したデフォルト値はHash#defaultで参照できます。
...fnone はキーに対
応する値が存在しない時のデフォルト値です。設定したデフォルト値はHash#defaultで参照できます。
ifnoneを省略した Hash.new は {} と同じです。
デフォルト値として、毎回同一のオブジェクトifnoneを返します......。
それにより、一箇所のデフォルト値の変更が他の値のデフォルト値にも影響します。
//emlist[][ruby]{
h = Hash.new([])
h[0] << 0
h[1] << 1
p h.default #=> [0, 1]
//}
これを避けるには、破壊的でないメソッドで再代入する必要が有ります......][ruby]{
h = Hash.new([])
p h[1] #=> []
p h[1].object_id #=> 6127150
p h[1] << "bar" #=> ["bar"]
p h[1] #=> ["bar"]
p h[2] #=> ["bar"]
p h[2].object_id #=> 6127150
p h #=> {}
h = Hash.new([].freeze)
h[0... -
PStore
# fetch(name , default = PStore :: Error) -> object (18137.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#[]... -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (198.0) -
1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))
...を返すことができます。
: 多重代入 [change]
多重代入の規則を見直しました。
# # derived from sample/test.rb
# a = *[]; p a # special case
# def f; yield; end; f {|a| p a} # add (warning)
# def r; return; end; a = r(); p a
#......|Array/transpose>)) [new]
追加
: ((<Array#zip|Enumerable/zip>)) [new]
: ((<Enumerable#zip|Enumerable/zip>)) [new]
追加
: ((<Array#fetch|Array/fetch>)) [new]
追加
: ((<Array#insert|Array/insert>)) [new]
追加 ((<ruby-talk:14289>))
(({ary[n,0] = [other,...]})) と同......((<ENV/ENV.clear>)) [new]
: ((<ENV/ENV.shift>)) [new]
: ((<ENV/ENV.invert>)) [new]
: ((<ENV/ENV.replace>)) [new]
: ((<ENV/ENV.update>)) [new]
((<Hash>)) との互換性のために定義されました。
=== Enumerable
: ((<Enumerable#partition|Enumerable/partition>)) [new]
追加
: ((<Enu... -
TSort
# each _ strongly _ connected _ component _ from(node , id _ map={} , stack=[]) -> Enumerator (112.0) -
node から到達可能な強連結成分についてのイテレータです。
...能なノードを表示する][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
non_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
non_sort.each_strongly_connected_component{|nodes|
p nodes... -
TSort
# each _ strongly _ connected _ component _ from(node , id _ map={} , stack=[]) {|nodes| . . . } -> () (112.0) -
node から到達可能な強連結成分についてのイテレータです。
...能なノードを表示する][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
non_sort = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
non_sort.each_strongly_connected_component{|nodes|
p nodes... -
tsort (18.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_c......単純な `make' に似たツールは以下のように実装できます。
//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] = [tripl...