種類
- インスタンスメソッド (44)
- 文書 (32)
ライブラリ
- ビルトイン (44)
モジュール
- Enumerable (44)
キーワード
-
NEWS for Ruby 2
. 2 . 0 (10) - Ruby用語集 (11)
-
ruby 1
. 9 feature (11)
検索結果
先頭5件
-
Enumerable
# max _ by -> Enumerator (18164.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...erable#max と Enumerable#max_by の
違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。
ブロックを省略した場合は Enumerator を返します。
@param n 取得する要素数。
//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # =>......"horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}
//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #<Enumerator: ["albatross", "dog", "horse"]:max_by(2)>
a.max_by(2) {|x| x.length } # => ["albatross", "horse"]
//}
//emlist[例: enum.max_by(n)......Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| 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 =... -
Enumerable
# max _ by {|item| . . . } -> object | nil (18164.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...erable#max と Enumerable#max_by の
違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。
ブロックを省略した場合は Enumerator を返します。
@param n 取得する要素数。
//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # =>......"horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}
//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #<Enumerator: ["albatross", "dog", "horse"]:max_by(2)>
a.max_by(2) {|x| x.length } # => ["albatross", "horse"]
//}
//emlist[例: enum.max_by(n)......Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| 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 =... -
Enumerable
# max _ by(n) -> Enumerator (18164.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...erable#max と Enumerable#max_by の
違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。
ブロックを省略した場合は Enumerator を返します。
@param n 取得する要素数。
//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # =>......"horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}
//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #<Enumerator: ["albatross", "dog", "horse"]:max_by(2)>
a.max_by(2) {|x| x.length } # => ["albatross", "horse"]
//}
//emlist[例: enum.max_by(n)......Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| 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 =... -
Enumerable
# max _ by(n) {|item| . . . } -> Array (18164.0) -
各要素を順番にブロックに渡して実行し、 その評価結果を <=> で比較して、 最大であった値に対応する元の要素、もしくは最大の n 要素が降順で入った配列を返します。
...erable#max と Enumerable#max_by の
違いは Enumerable#sort と Enumerable#sort_by の違いと同じです。
ブロックを省略した場合は Enumerator を返します。
@param n 取得する要素数。
//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # =>......"horse"]:max_by>
a.max_by { |x| x.length } # => "albatross"
//}
//emlist[例][ruby]{
a = %w[albatross dog horse]
a.max_by(2) # => #<Enumerator: ["albatross", "dog", "horse"]:max_by(2)>
a.max_by(2) {|x| x.length } # => ["albatross", "horse"]
//}
//emlist[例: enum.max_by(n)......Information Processing Letters
# Volume 97, Issue 5 (16 March 2006)
def wsample(n)
self.max_by(n) {|v| 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 =... -
NEWS for Ruby 2
. 2 . 0 (30.0) -
NEWS for Ruby 2.2.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...* 追加: Enumerable#slice_after
* 追加: Enumerable#slice_when
* 拡張: Enumerable#min, Enumerable#min_by, Enumerable#max, Enumerable#max_by
は複数の値を返すためのオプションをサポートしました
* Float
* 追加: Float#next_float
* 追加: Float#p......い。
* Math
* 非互換: Math.#log は 基底が 0 より小さいとき NaN を返すかわりに Math::DomainError を発生させます。
2つの引数に両方とも 0 が指定された場合、負の無限大ではなく NaN を返します。
* 非互換: Math.#atan2 は2......mParser という新しいパーサーを追加しました
=== 標準添付ライブラリの互換性 (機能追加とバグ修正を除く)
* mathn
* 非推奨の警告を表示するようになりました 10169
* ext/date/lib/date/format.rb
* 空だったので削除されまし... -
ruby 1
. 9 feature (24.0) -
ruby 1.9 feature ruby version 1.9.0 は開発版です。 以下にあげる機能は将来削除されたり互換性のない仕様変更がなされるかもしれません。 1.9.1 以降は安定版です。 バグ修正がメインになります。
...ました [new]
#: VIS_MASK が 16
: ancestors にモジュールが複数回挿入できるようになりました
: Math#log2 追加 ((<ruby-talk:191237>)) [new]
: Math#log にオプショナルな第2引数 base 追加 ((<ruby-talk:191308>)) [compat]
: Array#flatten, Array#flatten! が......加。((<ruby-core:03195>))
=== 2004-07-14
: Enumerable#max_by [new]
: Enumerable#min_by [new]
ブロックの結果を大小比較し、その最大値、最小値を示す要素を返します。
p [1,2,3,4,5].max_by {|v| -v}
# => ruby 1.9.0 (2004-07-17) [i586-linux]... -
Ruby用語集 (18.0)
-
Ruby用語集 A B C D E F G I J M N O R S Y
...ターメソッドでは繰り返したい処理をブロックで与える。
また、Enumerable#sort_by、Enumerable#group_by、
Enumerable#max_by などのように、要素に対する「評価関数」
としてブロックを要求するメソッドもある。
Kernel.#open メソッ......dule function
モジュールのインスタンスメソッドおよび特異メソッドとして二重に定義されている
メソッド。Math モジュールのメソッドなどがこれにあたる。
Module#module_function を使って簡単に定義できる。
: 文字列
: strin......プログラム中に直接記述された値のこと。3.14 や "foo" や /\d+/ はリテラル
だが、1 + 2 はリテラルではない。
Math::PI も定数参照なのでリテラルではない。
文字列リテラルが式展開を含む場合、実行時まで値が確定しな...