要約
等差数列を提供するためのクラス。
ArithmeticSequenceオブジェクトは、Numeric#step, Range#step によって生成されます。
目次
継承しているメソッド
- Enumeratorから継承している特異メソッド
- Enumeratorから継承しているメソッド
- Enumerableから継承しているメソッド
-
- all?
- any?
- chain
- chunk
- chunk_while
- collect
- collect_concat
- compact
- count
- cycle
- detect
- drop
- drop_while
- each_cons
- each_entry
- each_slice
- each_with_index
- each_with_object
- entries
- filter
- filter_map
- find
- find_all
- find_index
- flat_map
- grep
- grep_v
- group_by
- include?
- inject
- lazy
- map
- max
- max_by
- member?
- min
- min_by
- minmax
- minmax_by
- none?
- one?
- partition
- reduce
- reject
- reverse_each
- select
- slice_after
- slice_before
- slice_when
- sort
- sort_by
- sum
- take
- take_while
- tally
- to_a
- to_h
- to_set
- uniq
- zip
インスタンスメソッド
self == other -> boolRuby 2.6.0 から[permalink][rdoc][edit]-
Enumerable::ArithmeticSequence として等しいか判定します。
other が Enumerable::ArithmeticSequence で begin, end, step, exclude_end? が等しい時に true を返します。
- [PARAM]
other: - 自身と比較する Enumerable::ArithmeticSequence
- [PARAM]
begin -> Numeric | nilRuby 2.6.0 から[permalink][rdoc][edit]-
初項 (始端) を返します。
[SEE_ALSO] Enumerator::ArithmeticSequence#end
each {|n| ... } -> selfRuby 2.6.0 から[permalink][rdoc][edit]each -> self-
各要素に対してブロックを評価します。
- [RETURN]
- self を返します。
end -> Numeric | nilRuby 2.6.0 から[permalink][rdoc][edit]-
数列の終端の値を返します。終端がない場合は nil を返します。
自身は begin を初項として step ずつ加算して要素を生成しますが、 end はあくまで元になった範囲の終端の値であり、 数列が実際に生成する最後の要素と一致するとは限りません。 step の刻み幅によって end にちょうど到達しない場合や、 Enumerator::ArithmeticSequence#exclude_end? が真で end 自体が数列から除外される場合があるためです。
例: end と実際の最後の要素が一致する場合
例: step が end にちょうど到達しない場合s = (1..10).step(3) p s.end # => 10 p s.to_a # => [1, 4, 7, 10]
例: exclude_end? が真で end が除外される場合s = (1..10).step(4) p s.end # => 10 p s.to_a # => [1, 5, 9]s = (1...10).step(3) p s.end # => 10 p s.exclude_end? # => true p s.to_a # => [1, 4, 7][SEE_ALSO] Enumerator::ArithmeticSequence#begin
[SEE_ALSO] Enumerator::ArithmeticSequence#step
[SEE_ALSO] Enumerator::ArithmeticSequence#exclude_end?
[SEE_ALSO] Enumerator::ArithmeticSequence#last
exclude_end? -> boolRuby 2.6.0 から[permalink][rdoc][edit]-
末項(終端)を含まないとき真を返します。
first -> Numeric | nilRuby 2.6.0 から[permalink][rdoc][edit]first(n) -> [Numeric]-
等差数列の最初の要素、もしくは最初の n 要素を返します。
- [PARAM]
n: - 取得する要素数。
- [PARAM]
hash -> IntegerRuby 2.6.0 から[permalink][rdoc][edit]-
自身のハッシュ値を返します。
begin, end, step, exclude_end? が等しい Enumerable::ArithmeticSequence は同じハッシュ値を返します。
inspect -> StringRuby 2.6.0 から[permalink][rdoc][edit]-
自身を人間が読みやすい形の文字列表現にして返します。
last -> Numeric | nilRuby 2.6.0 から[permalink][rdoc][edit]last(n) -> [Numeric]-
等差数列の最後の要素、もしくは最後の n 要素を返します。
- [PARAM]
n: - 取得する要素数。
- [PARAM]
size -> Integer | nilRuby 2.6.0 から[permalink][rdoc][edit]-
有限なら要素数を返します。そうでなければ nil を返します。
- [RETURN]
- 要素数または nil を返します。
step -> NumericRuby 2.6.0 から[permalink][rdoc][edit]-
公差 (各ステップの大きさ) を返します。