るりまサーチ

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

別のキーワード

  1. _builtin max
  2. enumerable max
  3. _builtin max_by
  4. enumerable max_by
  5. range max

ライブラリ

モジュール

キーワード

検索結果

<< < 1 2 3 4 ... > >>

Enumerable#max(n) -> Array (18118.0)

最大の要素、もしくは最大の n 要素が入った降順の配列を返します。 全要素が互いに <=> メソッドで比較できることを仮定しています。

...配列を返します。
該当する要素が複数存在する場合、どの要素を返すかは不定です。

@param n 取得する要素数。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max # => "horse"
a.max(2) # => ["horse", "dog"]
//}...

Enumerable#max(n) {|a, b| ... } -> Array (18118.0)

ブロックの評価結果で各要素の大小判定を行い、最大の要素、もしくは最大の n 要素が入った降順の配列を返します。 引数を指定しない形式では要素が存在しなければ nil を返します。 引数を指定する形式では、空の配列を返します。

...tanaka", 33),
Person.new("tanaka", 11)
]

# 年齢が最大、名前が最小
people.max { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => #<Person:0x007fc54b0240a0 @name="sato", @age=55>
people.max(2) { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => [#<Person:0x007fc5...

Range#max {|a, b| ... } -> object | nil (18117.0)

ブロックの評価結果で範囲内の各要素の大小判定を行い、最大の要素を返しま す。範囲内に要素が存在しなければ nil を返します。

...の整数
を、期待しています。


@raise TypeError ブロックが整数以外を返したときに発生します。

@see Range#last, Range#min, Enumerable#max

//emlist[例][ruby]{
h = { 1 => "C", 2 => "Go", 3 => "Ruby" }
(1..3).max { |a, b| h[a].length <=> h[b].length } # => 3
//}...

Thread::SizedQueue#max -> Integer (18107.0)

キューの最大サイズを返します。

...キューの最大サイズを返します。

//emlist[例][ruby]{
q = SizedQueue.new(4)
q.max # => 4
//}...

Enumerable#max_by -> Enumerator (6164.0)

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

...

Enumerable#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)...
...is
# Weighted random sampling with a reservoir
# 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
}
#...

絞り込み条件を変える

Enumerable#max_by {|item| ... } -> object | nil (6164.0)

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

...

Enumerable#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)...
...is
# Weighted random sampling with a reservoir
# 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
}
#...

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

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

...

Enumerable#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)...
...is
# Weighted random sampling with a reservoir
# 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
}
#...

Enumerable#max_by(n) {|item| ... } -> Array (6164.0)

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

...

Enumerable#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)...
...is
# Weighted random sampling with a reservoir
# 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
}
#...

JSON::State#max_nesting -> Integer (6125.0)

生成される JSON 形式の文字列のネストの深さの最大値を返します。

...ew(max_nesting: 2)
json_state.max_nesting # => 2
JSON.generate([[]], json_state)
JSON.generate([[[]]], json_state) # => JSON::NestingError
//}

//emlist[例 ネストの深さチェックを行わない][ruby]{
require "json"

json_state = JSON::State.new(max_nesting: 0)
json_state.max_ne...

JSON::State#max_nesting=(depth) (6125.0)

生成される JSON 形式の文字列のネストの深さの最大値をセットします。

...いません。

//emlist[例][ruby]{
require "json"

json_state = JSON::State.new(max_nesting: 2)
json_state.max_nesting # => 2
JSON.generate([[]], json_state)
json_state.max_nesting = 3
json_state.max_nesting # => 3
JSON.generate([[[[]]]], json_state) # => JSON::NestingError...

絞り込み条件を変える

Thread::SizedQueue#max=(n) (6119.0)

キューの最大サイズを設定します。

...キューの最大サイズを設定します。

@param n キューの最大サイズを指定します。

//emlist[例][ruby]{
q = SizedQueue.new(4)
q.max # => 4
q.max = 5
q.max # => 5
//}...
<< < 1 2 3 4 ... > >>