るりまサーチ

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

別のキーワード

  1. openssl p
  2. openssl p=
  3. fileutils mkdir_p
  4. dsa p
  5. kernel p

ライブラリ

モジュール

キーワード

検索結果

<< < ... 11 12 13 >>

Enumerable#max_by -> Enumerator (9.0)

各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。

...違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。

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

@param n 取得する要素数。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # => #<Enumerator: ["albatross", "dog", "...
...は、Enumerable#wsampleを使用します。][ruby]{
module Enumerable
# weighted random sampling.
#
# Pavlos S. Efraimidis, Paul G. Spirakis
# Weighted random sampling with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_b...
...| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a is 20000 samples from e.
p
a.length #=> 20000
h = a.group_by {|x| x }
-10.upto(10) {|x| puts "*" * (h[x].length/30.0).to_i if h[x] }
#=> *
# ***
# ******
#...

Enumerable#max_by(n) -> Enumerator (9.0)

各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。

...違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。

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

@param n 取得する要素数。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # => #<Enumerator: ["albatross", "dog", "...
...は、Enumerable#wsampleを使用します。][ruby]{
module Enumerable
# weighted random sampling.
#
# Pavlos S. Efraimidis, Paul G. Spirakis
# Weighted random sampling with a reservoir
# Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_b...
...| rand ** (1.0/yield(v)) }
end
end
e = (-20..20).to_a*10000
a = e.wsample(20000) {|x|
Math.exp(-(x/5.0)**2) # normal distribution
}
# a is 20000 samples from e.
p
a.length #=> 20000
h = a.group_by {|x| x }
-10.upto(10) {|x| puts "*" * (h[x].length/30.0).to_i if h[x] }
#=> *
# ***
# ******
#...

Dir#each -> Enumerator (8.0)

ディレクトリの各エントリを表す文字列を引数として、ブロックを評価します。

...えられなかった場合、各エントリを文字列として保持する
Enumerator
オブジェクトを返します。

@raise IOError 既に自身が close している場合に発生します。

//emlist[例][ruby]{
Dir.open('.').each{|f|
p
f
}
#=> "."
# ".."
# "bar"
# "foo"
//}...
...場合、各エントリを文字列として保持する
Enumerator
オブジェクトを返します。

@raise IOError 既に自身が close している場合に発生します。

//emlist[例][ruby]{
Dir.open('.').each{|f|
p
f
}
#=> "."
# ".."
# "bar"
# "foo"
//}

@see Dir#each_child...

Dir#each_child -> Enumerator (8.0)

ディレクトリの "." と ".." をのぞく各エントリを表す文字列を引数として、 ブロックを評価します。

...合、各エントリを文字列として保持する
Enumerator
オブジェクトを返します。

@raise IOError 既に self が close している場合に発生します。

//emlist[例][ruby]{
Dir.open('.').each_child{|f|
p
f
}
#=> "bar"
# "foo"
//}

@see Dir#each
@see Dir.each_child...

Range#%(s) -> Enumerator (8.0)

範囲内の要素を s おきに繰り返します。

...範囲内の要素を s おきに繰り返します。

@param s 各ステップの大きさを数値で指定します。負の数を指定することもできます。
@return ブロックを指定した時は self を返します。
@return ブロックを指定しなかった時かつ数値の...
...Range の時は Enumerator::ArithmeticSequence を返します。
@return ブロックを指定しなかったその他の Range の時は Enumerator を返します。(例: String の Range)

//emlist[例][ruby]{
("a" .. "f").step(2) {|v| p v}
# => "a"
# "c"
# "e"
//}...

絞り込み条件を変える

Range#%(s) -> Enumerator::ArithmeticSequence (8.0)

範囲内の要素を s おきに繰り返します。

...範囲内の要素を s おきに繰り返します。

@param s 各ステップの大きさを数値で指定します。負の数を指定することもできます。
@return ブロックを指定した時は self を返します。
@return ブロックを指定しなかった時かつ数値の...
...Range の時は Enumerator::ArithmeticSequence を返します。
@return ブロックを指定しなかったその他の Range の時は Enumerator を返します。(例: String の Range)

//emlist[例][ruby]{
("a" .. "f").step(2) {|v| p v}
# => "a"
# "c"
# "e"
//}...
<< < ... 11 12 13 >>