るりまサーチ

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

別のキーワード

  1. erb u
  2. util u
  3. matrix u
  4. _builtin koi8_u
  5. encoding koi8_u

ライブラリ

クラス

モジュール

検索結果

<< 1 2 3 > >>

Matrix#each(which = :all) -> Enumerator (18227.0)

行列の各要素を引数としてブロックを呼び出します。

...:upper対角成分とそれより上側の部分
* :strict_lower 対角成分の下側
* :strict_upper 対角成分の上側

ブロックを省略した場合、 Enumerator を返します。

//emlist[例][ruby]{
require 'matrix'
Matrix[ [1,2], [3,4] ].each { |e| puts e }
# => prints the numb...
...ers 1 to 4
Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3]
//}

@param which どの要素に対してブロックを呼び出すのかを Symbol で指定します
@see Matrix#each_with_index, Matrix#map...

Matrix#map(which = :all) -> Enumerator (15233.0)

行列の各要素に対してブロックの適用を繰り返した結果を、要素として持つ行列を生成します。

...umerator を返します。

@param which which に以下の Symbol を指定することで、
引数として使われる要素を限定できます。
デフォルトは、:all (全ての要素)です。
指定できる Symbol の詳細は、 Matrix#each...
...の項目を参照して下さい。

//emlist[例][ruby]{
require 'matrix'

m = Matrix[[1, 2], [3, 4]]
p m.map { |x| x + 100 } # => Matrix[[101, 102], [103, 104]]
p m.map(:diagonal) { |x| x * 10 } # => Matrix[[10, 2], [3, 40]]
//}

@see Matrix#each, Matrix#map!...

Matrix#map -> Enumerator (15215.0)

行列の各要素に対してブロックの適用を繰り返した結果を、要素として持つ行列を生成します。

...適用を繰り返した結果を、要素として持つ行列を生成します。

ブロックがない場合、 Enumerator を返します。


//emlist[例][ruby]{
require 'matrix'

m = Matrix[[1, 2], [3, 4]]
p m.map { |x| x + 100 } # => Matrix[[101, 102], [103, 104]]
//}

@see Matrix#each...

Enumerator::Lazy#enum_for(method = :each, *args) -> Enumerator::Lazy (9323.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...うに、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0...
...to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum のおかげで、repeat の返り値は
# もとが Enumerator のときは Enumerator...

Enumerator::Lazy#enum_for(method = :each, *args) {|*args| block} -> Enumerator::Lazy (9323.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...うに、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0...
...to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum のおかげで、repeat の返り値は
# もとが Enumerator のときは Enumerator...

絞り込み条件を変える

Enumerator::Lazy#to_enum(method = :each, *args) -> Enumerator::Lazy (9323.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...うに、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0...
...to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum のおかげで、repeat の返り値は
# もとが Enumerator のときは Enumerator...

Enumerator::Lazy#to_enum(method = :each, *args) {|*args| block} -> Enumerator::Lazy (9323.0)

Object#to_enum と同じですが、Enumerator::Lazy を返します。

...Object#to_enum と同じですが、Enumerator::Lazy を返します。

to_enum は「ブロック付きで呼ぶとループを実行し、ブロックを省略した場合は
Enumerator を返す」ようなメソッドを定義するときによく使われます。
このときに lazy 性が...
...うに、Lazy#to_enum は
素のEnumerator ではなく Enumerator::Lazy を返すようになっています。

//emlist[例][ruby]{
module Enumerable
# 要素をn回ずつ繰り返すメソッド
# 例:[1,2,3].repeat(2) #=> [1,1,2,2,3,3]
def repeat(n)
raise ArgumentError if n < 0...
...to_enum(:repeat, n)
end
end
end

r = 1..10
p r.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

r = 1..Float::INFINITY
p r.lazy.map{|n| n**2}.repeat(2).first(5)
#=> [1, 1, 4, 4, 9]

# Lazy#to_enum のおかげで、repeat の返り値は
# もとが Enumerator のときは Enumerator...

Enumerable#sum(init=0) -> object (9113.0)

要素の合計を返します。

...selfが空の場合、initを返します。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum {|k, v| k * v } # => 50
(1..10).sum # => 55
(1..10).sum {|v| v * 2 } # => 110
('a'..'z').sum # => TypeError
//}

init 引数を明...
...す。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum([]) #=> [1, 10, 2, 20]
"a\nb\nc".each_line.lazy.map(&:chomp).sum("") #=> "abc"
[[1], [[2]], [3]].sum([]) #=> [1, [2], 3]
//}

"+" メソッドが再定義されている場合、Enumerable#sum は再定義を無視す...
...ることがあります(例えばInteger#+)。

@see Array#sum...

Enumerable#sum(init=0) {|e| expr } -> object (9113.0)

要素の合計を返します。

...selfが空の場合、initを返します。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum {|k, v| k * v } # => 50
(1..10).sum # => 55
(1..10).sum {|v| v * 2 } # => 110
('a'..'z').sum # => TypeError
//}

init 引数を明...
...す。

//emlist[例][ruby]{
{ 1 => 10, 2 => 20 }.sum([]) #=> [1, 10, 2, 20]
"a\nb\nc".each_line.lazy.map(&:chomp).sum("") #=> "abc"
[[1], [[2]], [3]].sum([]) #=> [1, [2], 3]
//}

"+" メソッドが再定義されている場合、Enumerable#sum は再定義を無視す...
...ることがあります(例えばInteger#+)。

@see Array#sum...

TSort#each_strongly_connected_component_from(node, id_map={}, stack=[]) -> Enumerator (6365.0)

node から到達可能な強連結成分についてのイテレータです。

...せん。

each
_strongly_connected_component_from は
tsort_each_node を呼びません。

@param node ノードを指定します。

//emlist[例 到達可能なノードを表示する][ruby]{
require 'tsort'

class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(no...
...de, &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
nodes.each {|node|
non_sort.each_strongly_connected_component_from(node){|ns|
printf("%s -> %s\n", node, ns.join(","))
}
}...
...}

#出力
#=> [4]
#=> 4 -> 4
#=> [2, 3]
#=> 2 -> 4
#=> 2 -> 2,3
#=> 3 -> 4
#=> 3 -> 3,2
#=> [1]
#=> 1 -> 4
#=> 1 -> 2,3
#=> 1 -> 1
//}

@see TSort.each_strongly_connected_component_from...

絞り込み条件を変える

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

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

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

ブロックを指定した場合は Enumerator#size がブロックの評価結果を返
します。ブロックパラメータは引数 args です。


@param method メソッド名の文字列かシンボルです。
@param 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]{
module Enumerable...
...aise ArgumentError, "#{n} is negative!" if n < 0
u
nless block_given?
# __method__ はここでは :repeat
return to_enum(__method__, n) do
# size メソッドが nil でなければ size * n を返す。
sz = size
sz * n if sz
end
end
each
do |*v...
<< 1 2 3 > >>