ライブラリ
クラス
-
ARGF
. class (48) - Array (201)
- CSV (60)
-
CSV
:: Table (36) - Dir (158)
- Enumerator (182)
-
Enumerator
:: Lazy (183) -
Enumerator
:: Yielder (30) - File (24)
- Hash (117)
- IO (192)
- Matrix (196)
- Module (36)
- Object (72)
- PP (12)
- Pathname (75)
- Prime (24)
-
Prime
:: PseudoPrimeGenerator (48) -
REXML
:: Attributes (24) -
REXML
:: Element (24) -
REXML
:: Elements (24) -
REXML
:: XPath (12) - Range (40)
- Set (168)
- String (260)
- StringIO (100)
- Struct (48)
- Thread (12)
-
Thread
:: Queue (82) -
Thread
:: SizedQueue (46) - WIN32OLE (12)
-
WIN32OLE
_ EVENT (24) -
WIN32OLE
_ TYPE (12)
モジュール
- Enumerable (487)
- Kernel (72)
-
Net
:: HTTPHeader (72) - ObjectSpace (72)
- TSort (186)
オブジェクト
- ENV (36)
キーワード
-
$ CHILD _ STATUS (12) -
$ LAST _ PAREN _ MATCH (12) -
$ _ (12) -
$ stdin (12) - & (12)
- + (19)
- - (12)
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - << (12)
- ConditionVariable (12)
- DATA (12)
- Enumerator (12)
- Fiber (12)
- Lazy (12)
-
NEWS for Ruby 2
. 0 . 0 (12) -
NEWS for Ruby 2
. 2 . 0 (11) -
NEWS for Ruby 2
. 3 . 0 (10) -
NEWS for Ruby 2
. 4 . 0 (9) -
NEWS for Ruby 3
. 1 . 0 (4) - Queue (12)
-
WIN32OLE
_ EVENT (12) - [] (12)
- ^ (12)
-
append
_ features (12) - bytes (38)
- chars (24)
- children (16)
- chunk (36)
-
chunk
_ while (12) - clear (12)
- close (10)
- closed? (10)
- codepoints (24)
- collect (24)
- collect! (38)
-
collect
_ concat (12) - count (36)
-
default
_ event _ sources (12) -
delete
_ if (24) - deq (24)
- difference (12)
-
each
_ attribute (12) -
each
_ byte (72) -
each
_ capitalized _ name (12) -
each
_ char (36) -
each
_ child (70) -
each
_ codepoint (72) -
each
_ cons (24) -
each
_ element _ with _ attribute (12) -
each
_ element _ with _ text (12) -
each
_ entry (39) -
each
_ filename (12) -
each
_ grapheme _ cluster (16) -
each
_ header (12) -
each
_ index (12) -
each
_ key (36) -
each
_ line (132) -
each
_ name (12) -
each
_ object (48) -
each
_ pair (48) -
each
_ slice (24) -
each
_ strongly _ connected _ component (46) -
each
_ strongly _ connected _ component _ from (46) -
each
_ value (24) -
each
_ with _ index (72) -
each
_ with _ object (24) - eager (6)
- entries (12)
-
enum
_ for (48) -
extend
_ object (12) - feed (12)
- filter! (14)
-
find
_ index (36) - first (24)
-
flat
_ map (12) - fnmatch (12)
- fnmatch? (12)
-
force
_ quotes? (12) - foreach (96)
- getoptlong (12)
-
grapheme
_ clusters (16) - handler= (12)
- index (36)
- inject (36)
-
inplace
_ mode (12) -
instance
_ method (12) - intersection (12)
- invert (12)
-
keep
_ if (19) - length (12)
- lines (38)
- map (24)
- map! (38)
-
memsize
_ of _ all (12) - merge (12)
- new (67)
- next (12)
-
next
_ values (12) -
ole
_ query _ interface (12) - optparse (12)
- pack (21)
- pack テンプレート文字列 (12)
- parse (24)
-
peek
_ values (12) - pop (24)
- pos (12)
- push (12)
-
reachable
_ objects _ from (12) - reduce (36)
- reject! (24)
- replace (12)
-
respond
_ to? (12) -
reverse
_ each (52) - rewind (12)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 2 feature (12) -
ruby 1
. 8 . 3 feature (12) -
ruby 1
. 8 . 4 feature (12) - select! (24)
- seplist (12)
- shift (24)
- size (12)
-
slice
_ after (46) -
slice
_ before (60) -
slice
_ when (23) -
strongly
_ connected _ components (24) - subtract (12)
- sum (36)
- take (12)
-
take
_ while (24) - tell (12)
- test (24)
-
to
_ a (24) -
to
_ enum (48) -
to
_ h (19) -
to
_ proc (6) - tsort (36)
-
tsort
_ each (46) - union (12)
- unpack (12)
- upto (12)
-
with
_ index (48) -
with
_ object (24) - yaml (12)
- yield (12)
- zip (48)
- | (12)
- 制御構造 (12)
検索結果
先頭5件
-
tsort (26174.0)
-
tsort はトポロジカルソートと強連結成分に関するモジュールを提供します。
...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],......=>[]}.tsort
#=> [3, 2, 1, 4]
{1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}.strongly_connected_components
#=> [[4], [2, 3], [1]]
//}
=== より現実的な例
非常に単純な `make' に似たツールは以下のように実装できます。
//emlist[][ruby]{
require 'tsort'
class Make
def initialize......default = []
end
def rule(outputs, inputs=[], &block)
triple = [outputs, inputs, block]
outputs.each {|f| @dep[f] = [triple]}
@dep[triple] = inputs
end
def build(target)
each_strongly_connected_component_from(target) {|ns|
if ns.length != 1
fs = ns.delete_if {... -
Enumerator
# each { . . . } -> object (21294.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...る引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"......# "Hacker"
str.scan(/\w+/) {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
//}
//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/)......orld!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end
enum = obj.to_enum :each_arg, :a, :x
enum.each.to_a... -
Enumerator
# each(*args) -> Enumerator (21294.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...る引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"......# "Hacker"
str.scan(/\w+/) {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
//}
//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/)......orld!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end
enum = obj.to_enum :each_arg, :a, :x
enum.each.to_a... -
Enumerator
# each(*args) { . . . } -> object (21294.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...る引数
//emlist[例1][ruby]{
str = "Yet Another Ruby Hacker"
enum = Enumerator.new {|y| str.scan(/\w+/) {|w| y << w }}
enum.each {|word| p word } # => "Yet"
# "Another"
# "Ruby"......# "Hacker"
str.scan(/\w+/) {|word| p word } # => "Yet"
# "Another"
# "Ruby"
# "Hacker"
//}
//emlist[例2][ruby]{
"Hello, world!".scan(/\w+/)......orld!".to_enum(:scan, /\w+/).to_a # => ["Hello", "world"]
"Hello, world!".to_enum(:scan).each(/\w+/).to_a # => ["Hello", "world"]
obj = Object.new
def obj.each_arg(a, b=:b, *rest)
yield a
yield b
yield rest
:method_returned
end
enum = obj.to_enum :each_arg, :a, :x
enum.each.to_a... -
REXML
:: Elements # each(xpath = nil) {|element| . . . } -> [REXML :: Elements] (21237.0) -
全ての子要素に対しブロックを呼び出します。
...xpath を指定した場合には、その XPath 文字列に
マッチする要素に対しブロックを呼び出します。
REXML::XPath.each などとは異なり、要素以外の
テキストノードなどはすべて無視されることに注意してください。
@param xpath XPath......//emlist[][ruby]{
require 'rexml/document'
require 'rexml/xpath'
doc = REXML::Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>'
# <b/>,<c/>,<d/>,<b/>,<c/>, <d/> がブロックに渡される
doc.root.elements.each {|e|p e}
# <b/>, <b/> がブロックに渡される
doc.root.elements.each('b') {|......e|p e} #-> Yields b, b elements
# <b/>,<c/>,<d/>,<b/>,<c/>,<d/> がブロックに渡される
doc.root.elements.each('child::node()') {|e|p e}
# <b/>,<c/>,<d/>,"sean",<b/>,<c/>,<d/> がブロックに渡される
REXML::XPath.each(doc.root, 'child::node()'){|node| p node }
//}... -
Matrix
# each(which = :all) -> Enumerator (21226.0) -
行列の各要素を引数としてブロックを呼び出します。
...strict_lower 対角成分の下側
* :strict_upper 対角成分の上側
ブロックを省略した場合、 Enumerator を返します。
//emlist[例][ruby]{
require 'matrix'
Matrix[ [1,2], [3,4] ].each { |e| puts e }
# => prints the numbers 1 to 4
Matrix[ [1,2], [3,4] ].each(:strict_lower).t......o_a # => [3]
//}
@param which どの要素に対してブロックを呼び出すのかを Symbol で指定します
@see Matrix#each_with_index, Matrix#map... -
StringIO
# each(rs = $ / ) -> Enumerator (21222.0) -
自身から 1 行ずつ読み込み、それを引数として与えられたブロックを実行します。
...連続する改行を行の区切りとみなします(パラグラフモード)。
@raise IOError 自身が読み取り不可なら発生します。
//emlist[例][ruby]{
require "stringio"
a = StringIO.new("hoge\nfoo\n")
a.each{|l| p l }
#=> "hoge\n"
# "foo\n"
//}
@see $/
@see IO#each_line... -
Struct
# each -> Enumerator (21214.0) -
構造体の各メンバに対して繰り返します。
...述は Struct の下位クラスのインスタンスに対して呼び
出す事を想定しています。Struct.new は Struct の下位クラスを作成する点に
注意してください。
//emlist[例][ruby]{
Customer = Struct.new(:name, :address, :zip)
joe = Customer.new("Joe Smith", "12......3 Maple, Anytown NC", 12345)
joe.each {|x| puts(x) }
# => Joe Smith
# 123 Maple, Anytown NC
# 12345
//}... -
REXML
:: XPath . each(element , path = nil , namespaces = {} , variables = {}) {|e| . . . } -> () (21213.0) -
element の path で指定した XPath 文字列にマッチする各ノード に対してブロックを呼び出します。
...element の path で指定した XPath 文字列にマッチする各ノード
に対してブロックを呼び出します。
path に相対パスを指定した場合は element からの相対位置で
マッチするノードを探します。
絶対パスを指定した場合は element が......用います。
@param element 要素(REXML::Element)
@param path XPath文字列
@param namespace 名前空間とURLの対応付け
@param variables 変数名とその値の対応付け
//emlist[][ruby]{
require 'rexml/document'
doc = REXML::Document.new(<<EOS)
<root xmlns:x='1'>
<a>
<b>b1</......b>
<x:c />
<b>b2</b>
<d />
</a>
<b> b3 </b>
</root>
EOS
REXML::XPath.each(doc, "/root/a/b"){|e| p e.text }
# >> "b1"
# >> "b2"
//}...