るりまサーチ

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

別のキーワード

  1. _builtin <
  2. bigdecimal <
  3. float <
  4. complex <
  5. module <

ライブラリ

モジュール

キーワード

検索結果

<< 1 2 3 > >>

REXML::Elements#each(xpath = nil) {|element| ... } -> [REXML::Elements] (18174.0)

全ての子要素に対しブロックを呼び出します。

....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 }
//}...

REXML::Attributes#each {|name, value| ... } -> () (18120.0)

各属性の名前と値に対しブロックを呼び出します。

...<<EOS)
<
root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<
a foo:att='1' bar:att='2' att='&lt;'/>
<
/root>
EOS
a = doc.get_elements("/root/a").first

a.attributes.each do |name, value|
p [name, value]
end

# => ["foo:att", "1"]
# => ["bar:att", "2"]
# => ["att", "<...

REXML::Element#each_element_with_attribute(key, value = nil, max = 0, name = nil) {|element| ... } -> () (6168.0)

特定の属性を持つすべての子要素を引数としてブロックを呼び出します。

...REXML::Document.new("<a><b id='1'/><c id='2'/><d id='1'/><e/></a>")
doc.root.each_element_with_attribute('id'){|e| p e }
# >> <b id='1'/>
# >> <c id='2'/>
# >> <d id='1'/>
doc.root.each_element_with_attribute('id', '1'){|e| p e }
# >> <b id='1'/>
# >> <d id='1'/>
doc.root.each_element_with_attribut...
...e('id', '1', 1){|e| p e }
# >> <b id='1'/>
doc.root.each_element_with_attribute('id', '1', 0, 'd'){|e| p e }
# >> <d id='1'/>
//}...

REXML::Element#each_element_with_text(text = nil, max = 0, name = nil) {|element| ... } -> () (6168.0)

テキストを子ノードとして 持つすべての子要素を引数としてブロックを呼び出します。

...t.new '<a><b>b</b><c>b</c><d>d</d><e/></a>'
doc.root.each_element_with_text {|e|p e}
# >> <b> ... </>
# >> <c> ... </>
# >> <d> ... </>
doc.root.each_element_with_text('b'){|e|p e}
# >> <b> ... </>
# >> <c> ... </>
doc.root.each_element_with_text('b', 1){|e|p e}
# >> <b> ... </>
doc.root.each_elemen...
...t_with_text(nil, 0, 'd'){|e|p e}
# >> <d> ... </>
//}...

REXML::Attributes#each_attribute {|attribute| ... } -> () (6120.0)

各属性に対しブロックを呼び出します。

...quire 'rexml/document'

doc = REXML::Document.new(<<EOS)
<
root xmlns:foo="http://example.org/foo"
xmlns:bar="http://example.org/bar">
<
a foo:att='1' bar:att='2' att='&lt;'/>
<
/root>
EOS
a = doc.get_elements("/root/a").first

a.attributes.each_attribute do |attr|
p [attr.namespace, attr.nam...
...e, attr.value]
end
# => ["http://example.org/foo", "att", "1"]
# => ["http://example.org/bar", "att", "2"]
# => ["", "att", "<"]
//}...

絞り込み条件を変える

Enumerator::Yielder#<<(object) -> () (6119.0)

Enumerator.new で使うメソッドです。

...生成された Enumerator オブジェクトの each メソッドを呼ぶと
Enumerator::Yielder オブジェクトが渡されたブロックが実行され、
ブロック内の << が呼ばれるたびに each に渡されたブロックが
<
< に渡された値とともに繰り返されま...
...す。

//emlist[例][ruby]{
enum = Enumerator.new do |y|
y << 1
y << 2
y << 3
end

enum.each do |v|
p v
end
# => 1
# 2
# 3
//}...

WEBrick::HTTPUtils::FormData#each_data {|s| ... } (6114.0)

自身が表す各フォームデータを引数として、与えられたブロックを実行します。

...ムデータを引数として、与えられたブロックを実行します。

例:

require "webrick/cgi"
class MyCGI < WEBrick::CGI
def do_GET(req, res)
req.query['q'].each_data{|s|
p s
}
#=> "val1"
"val2"
"val3"
end
end
MyCGI.new.start()...

Object#enum_for(method = :each, *args) -> Enumerator (129.0)

Enumerator.new(self, method, *args) を返します。

...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
..., "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each
do |*val|
n.times...
...{ yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

Object#enum_for(method = :each, *args) {|*args| ... } -> Enumerator (129.0)

Enumerator.new(self, method, *args) を返します。

...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
..., "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each
do |*val|
n.times...
...{ yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

Object#to_enum(method = :each, *args) -> Enumerator (129.0)

Enumerator.new(self, method, *args) を返します。

...数です。

//emlist[][ruby]{
str = "xyz"

enum = str.enum_for(:each_byte)
p(a = enum.map{|b| '%02x' % b }) #=> ["78", "79", "7a"]

# protects an array from being modified
a = [1, 2, 3]
p(a.to_enum) #=> #<Enumerator: [1, 2, 3]:each>
//}

//emlist[例(ブロックを指定する場合)][ruby]{
modu...
..., "#{n} is negative!" if n < 0
unless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each
do |*val|
n.times...
...{ yield *val }
end
end
end

%i[hello world].repeat(2) { |w| puts w }
# => 'hello', 'hello', 'world', 'world'
enum = (1..14).repeat(3)
# => #<Enumerator: 1..14:repeat(3)>
enum.first(4) # => [1, 1, 1, 2]
enum.size # => 42
//}

@see Enumerator, Enumerator#size...

絞り込み条件を変える

<< 1 2 3 > >>