< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #15092 has been updated by shevegen (Robert A. Heiler).
> Wouldn't the result be [1, 4, 7, 10, 13]?
Off-by-one is ... common. :)
A bit more on topic, Float::INFINITY is quite long. Could
we not use :infinity to refer to it in some methods or
something shorter? I think ruby users should not need to
have to know the leading "namespace" (Float) in order to
refer to a concept of infinity in ruby.
----------------------------------------
Feature #15092: Provide step count in Range constructor
https://bugs.ruby-lang.org/issues/15092#change-73954
* Author: v0dro (Sameer Deshmukh)
* Status: Feedback
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
I would like to propose making changes to the Range constructor so that a user can specify
a `step` count along with `start` and `stop`. Since Ruby 2.6 will introduce a `step` property
in Ranges anyway I think this will be a useful addition.
Here's my reasons for the changes:
When creating software libraries for numerical computing, it is common to query the data
container for values in a particular range at some given steps. For example, say I have the
following NArray object:
~~~ ruby
a = NArray.new([1,2,3,4,5,6,7,8,9,10,11,12])
~~~
And I want the values `1`, `4`, `7`, `10` and `12`, I can simply specify a Range like this:
~~~ ruby
r = Range.new 0, Float::INFINITY, 3 # start, stop (upto the end), step
a[r]
# => NArray([1, 4, 7, 10, 12])
~~~
This can possibly also be extended to `Array#[]` so that users can get ranges of values at
steps without much worry.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>