種類
- インスタンスメソッド (162)
- 特異メソッド (29)
クラス
- Array (19)
- Enumerator (106)
-
Enumerator
:: Lazy (11) -
Enumerator
:: Yielder (11) - String (22)
モジュール
- Enumerable (22)
キーワード
-
each
_ with _ object (22) - new (29)
- pack (19)
- sum (11)
- unpack (11)
-
with
_ index (22) -
with
_ object (22)
検索結果
先頭5件
-
Enumerator
# each -> self (26172.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...am 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"
#......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 # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |e......lm| elm } # => :method_returned
enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |elm| elm } # => :method_returned
//}... -
Enumerator
# each { . . . } -> object (26172.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...am 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"
#......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 # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |e......lm| elm } # => :method_returned
enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |elm| elm } # => :method_returned
//}... -
Enumerator
# each(*args) -> Enumerator (26172.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...am 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"
#......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 # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |e......lm| elm } # => :method_returned
enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |elm| elm } # => :method_returned
//}... -
Enumerator
# each(*args) { . . . } -> object (26172.0) -
生成時のパラメータに従ってブロックを繰り返します。 *args を渡した場合は、生成時のパラメータ内引数末尾へ *args を追加した状態で繰り返します。 ブロック付きで呼び出された場合は、 生成時に指定したイテレータの戻り値をそのまま返します。
...am 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"
#......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 # => [:a, :x, []]
enum.each.equal?(enum) # => true
enum.each { |e......lm| elm } # => :method_returned
enum.each(:y, :z).to_a # => [:a, :x, [:y, :z]]
enum.each(:y, :z).equal?(enum) # => false
enum.each(:y, :z) { |elm| elm } # => :method_returned
//}... -
Enumerator
:: Yielder # <<(object) -> () (26150.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
//}... -
Enumerable
# each _ with _ object(obj) -> Enumerator (14116.0) -
与えられた任意のオブジェクトと要素をブロックに渡し繰り返し、最初に与えられたオブジェクトを返します。
...返します。
ブロックを省略した場合は Enumerator を返します。
@param obj 任意のオブジェクトを指定します。
//emlist[例][ruby]{
evens = (1..10).each_with_object([]) {|i, a| a << i*2 }
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}
@see Enumerator#with_object... -
Enumerable
# each _ with _ object(obj) {|(*args) , memo _ obj| . . . } -> object (14116.0) -
与えられた任意のオブジェクトと要素をブロックに渡し繰り返し、最初に与えられたオブジェクトを返します。
...返します。
ブロックを省略した場合は Enumerator を返します。
@param obj 任意のオブジェクトを指定します。
//emlist[例][ruby]{
evens = (1..10).each_with_object([]) {|i, a| a << i*2 }
# => [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
//}
@see Enumerator#with_object... -
Enumerator
. new(obj , method = :each , *args) -> Enumerator (8134.0) -
オブジェクト obj について、 each の代わりに method という 名前のメソッドを使って繰り返すオブジェクトを生成して返します。 args を指定すると、 method の呼び出し時に渡されます。
...オブジェクト obj について、 each の代わりに method という
名前のメソッドを使って繰り返すオブジェクトを生成して返します。
args を指定すると、 method の呼び出し時に渡されます。
@param obj イテレータメソッドのレシーバ......method イテレータメソッドの名前を表すシンボルまたは文字列
@param args イテレータメソッドの呼び出しに渡す任意個の引数
//emlist[例][ruby]{
str = "xyz"
enum = Enumerator.new(str, :each_byte)
p enum.map {|b| '%02x' % b } # => ["78", "79", "7a"]
//}... -
Enumerator
. new(size=nil) {|y| . . . } -> Enumerator (8059.0) -
Enumerator オブジェクトを生成して返します。与えられたブロックは Enumerator::Yielder オブジェクトを 引数として実行されます。
...して each を呼ぶと、この生成時に指定されたブロックを
実行し、Yielder オブジェクトに対して << メソッドが呼ばれるたびに、
each に渡されたブロックが繰り返されます。
new に渡されたブロックが終了した時点で each の繰......り返しが終わります。
このときのブロックの返り値が each の返り値となります。
@param size 生成する Enumerator オブジェクトの要素数を指定します。
Integer、Float::INFINITY、Proc オブジェク
ト、nil のいずれかを......に参照されます。
//emlist[例][ruby]{
enum = Enumerator.new{|y|
(1..10).each{|i|
y << i if i % 5 == 0
}
}
enum.each{|i| p i }
#=> 5
# 10
fib = Enumerator.new { |y|
a = b = 1
loop {
y << a
a, b = b, a + b
}
}
p fib.take(10) #=> [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]... -
Array
# pack(template) -> String (8044.0) -
配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。
...sgn * Inf # ±∞ (positive/negative infinity)
else
NaN # 非数 (not a number)
end
else
fra += 1 << 23 # ゲタ
sgn * fra * 2**(exp-127-23) # 正規化数 (normalized number)
end
//}
: G
ビッグエンディアンの倍精......sgn * Inf # ±∞ (positive/negative infinity)
else
NaN # 非数 (not a number)
end
else
fra += 1 << 52 # ゲタ
sgn * fra * 2**(exp-1023-52) # 正規化数 (normalized number)
end
//}
: p
ヌル終端の文字列へのポイ......uby"
[82, 117, 98, 121].pack("c*") # => "Ruby"
s = ""
[82, 117, 98, 121].each {|c| s << c}
s # => "Ruby"
[82, 117, 98, 121].collect {|c| sprintf "%c", c}.join # => "Ruby"
[82, 117, 98, 121].inject("") {|s, c| s << c} # => "Ruby"
//}
: 文字列を数値(文字コード)の配列に変...