るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

モジュール

キーワード

検索結果

Numeric#nonzero? -> self | nil (21132.0)

自身がゼロの時 nil を返し、非ゼロの時 self を返します。

...ロの時 nil を返し、非ゼロの時 self を返します。

//emlist[例][ruby]{
p 10.nonzero? #=> 10
p 0.nonzero? #=> nil
p 0.0.nonzero? #=> nil
p Rational(0, 2).nonzero? #=> nil
//}

非ゼロの時に self を返すため、自身が 0 の時に他...
...理をさせたい場合に以
下のように記述する事もできます。

//emlist[例][ruby]{
a = %w( z Bb bB bb BB a aA Aa AA A )
b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b }
b #=> ["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"]
//}

@see Numeric#zero?...

Enumerable#max {|a, b| ... } -> object | nil (3013.0)

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

...ist[例][ruby]{
class Person
attr_reader :name, :age

def initialize(name, age)
@name = name
@age = age
end
end

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 11),
Person.new("suzuki", 55),
Person.new("suzuki", 33),
Person.new("suzuki", 11),...
...{ |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:0x007fc54b0240a0 @name="sato", @age=55>, #<Person:0x007fc54c033ea0 @name="suzuki", @age=55>]
//}...

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

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

...ist[例][ruby]{
class Person
attr_reader :name, :age

def initialize(name, age)
@name = name
@age = age
end
end

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 11),
Person.new("suzuki", 55),
Person.new("suzuki", 33),
Person.new("suzuki", 11),...
...{ |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:0x007fc54b0240a0 @name="sato", @age=55>, #<Person:0x007fc54c033ea0 @name="suzuki", @age=55>]
//}...

Enumerable#min {|a, b| ... } -> object | nil (3013.0)

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

...ist[例][ruby]{
class Person
attr_reader :name, :age

def initialize(name, age)
@name = name
@age = age
end
end

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 11),
Person.new("suzuki", 55),
Person.new("suzuki", 33),
Person.new("suzuki", 11),...
...y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => #<Person:0x007fd6f0824190 @name="tanaka", @age=11>

people.min(2) { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => [#<Person:0x007fb5899ef4a8 @name="tanaka", @age=11>, #<Person:0x007fb5899ef728 @name="suzuki", @age=11>]
//}

@...

Enumerable#min(n) {|a, b| ... } -> Array (3013.0)

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

...ist[例][ruby]{
class Person
attr_reader :name, :age

def initialize(name, age)
@name = name
@age = age
end
end

people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 11),
Person.new("suzuki", 55),
Person.new("suzuki", 33),
Person.new("suzuki", 11),...
...y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => #<Person:0x007fd6f0824190 @name="tanaka", @age=11>

people.min(2) { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => [#<Person:0x007fb5899ef4a8 @name="tanaka", @age=11>, #<Person:0x007fb5899ef728 @name="suzuki", @age=11>]
//}

@...

絞り込み条件を変える

Enumerable#max -> object | nil (3003.0)

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

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

@param n 取得する要素数。

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

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

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

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

@param n 取得する要素数。

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

Enumerable#min -> object | nil (3003.0)

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

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

@param n 取得する要素数。

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

Enumerable#min(n) -> Array (3003.0)

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

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

@param n 取得する要素数。

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