るりまサーチ

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

別のキーワード

  1. _builtin numerator
  2. numeric numerator
  3. float numerator
  4. integer numerator
  5. complex numerator

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 > >>

Integer#upto(max) -> Enumerator (18208.0)

self から max まで 1 ずつ増やしながら繰り返します。 self > max であれば何もしません。

...self から max まで 1 ずつ増やしながら繰り返します。
self > max であれば何もしません。

@param max 数値
@return self を返します。

//emlist[][ruby]{
5.upto(10) {|i| print i, " " } # => 5 6 7 8 9 10
//}

@see Integer#downto, Numeric#step, Integer#times...

Date#upto(max) -> Enumerator (18202.0)

このメソッドは、step(max, 1){|date| ...} と等価です。

このメソッドは、step(max, 1){|date| ...} と等価です。

@param max 日付オブジェクト

@see Date#step, Date#downto

Date#downto(min) -> Enumerator (106.0)

このメソッドは、step(min, -1){|date| ...} と等価です。

...このメソッドは、step(min, -1){|date| ...} と等価です。

@param min 日付オブジェクト

@see Date#step, Date#upto...

Date#step(limit, step = 1) -> Enumerator (106.0)

ブロックの評価を繰り返します。ブロックは日付オブジェクトをとります。 limit は日付オブジェクトでなければなりません、 また step は非零でなければなりません。

...評価を繰り返します。ブロックは日付オブジェクトをとります。
limit は日付オブジェクトでなければなりません、
また step は非零でなければなりません。

@param limit 日付オブジェクト
@param step 歩幅

@see Date#downto, Date#upto...

Enumerable#max_by -> Enumerator (106.0)

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

..._by の違いと同じです。

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

@param n 取得する要素数。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # => #<Enumerator: ["albatross", "dog", "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)は、重み付きランダムサンプリング...
...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 (106.0)

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

..._by の違いと同じです。

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

@param n 取得する要素数。

//emlist[例][ruby]{
a = %w(albatross dog horse)
a.max_by # => #<Enumerator: ["albatross", "dog", "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)は、重み付きランダムサンプリング...
...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#sort_by -> Enumerator (106.0)

ブロックの評価結果を <=> メソッドで比較することで、self を昇 順にソートします。ソートされた配列を新たに生成して返します。

...回数の検証結果を参照してみてください。

//emlist[][ruby]{
class Integer
def count
$n += 1
self
end
end

ary = []
1.upto(1000) {|v| ary << rand(v) }

$n = 0
ary.sort {|a,b| a.count <=> b.count }
p $n # => 18200

$n = 0
ary.sort_by {|v| v.count }
p $n #...
...できます。

//emlist[][ruby]{
i = 0
ary.sort_by {|v| [v, i += 1] }
//}

※ 比較結果が同じ要素は元の順序通りに並ぶソートを
「安定なソート (stable sort)」と言います。

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


@see Enumerable#sort...

Integer#downto(min) -> Enumerator (106.0)

self から min まで 1 ずつ減らしながらブロックを繰り返し実行します。 self < min であれば何もしません。

...で 1 ずつ減らしながらブロックを繰り返し実行します。
self < min であれば何もしません。

@param min 数値
@return self を返します。

//emlist[][ruby]{
5.downto(1) {|i| print i, " " } # => 5 4 3 2 1
//}

@see Integer#upto, Numeric#step, Integer#times...

Integer#times -> Enumerator (106.0)

self 回だけ繰り返します。 self が正の整数でない場合は何もしません。

...れます。

//emlist[][ruby]{
3.times { puts "Hello, World!" } # Hello, World! と3行続いて表示される。
0.times { puts "Hello, World!" } # 何も表示されない。
5.times {|n| print n } # 01234 と表示される。
//}

@see Integer#upto, Integer#downto, Numeric#step...

Numeric (12.0)

数値を表す抽象クラスです。Integer や Float などの数値クラス は Numeric のサブクラスとして実装されています。

...t_float | - - o - -
nonzero? | o - - - -
numerator
| o o o o o
odd? | - o - - -...
...to_s | - o o o o
truncate | o o o o -
upto
| - o - - -
zero? | o - o - -...

絞り込み条件を変える

<< 1 2 > >>