Issue #14044 has been updated by mrkn (Kenta Murata).


I want this feature for specifying a sliced view of a multi-dimensional array.
In Python, it can be represented by using slice notation or a slice object:

```python
>>> ary = numpy.arange(0, 36).reshape((6, 6))
>>> ary
array([[ 0,  1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10, 11],
       [12, 13, 14, 15, 16, 17],
       [18, 19, 20, 21, 22, 23],
       [24, 25, 26, 27, 28, 29],
       [30, 31, 32, 33, 34, 35]])
>>> ary[1:5:2, slice(1, 5, 2)]
array([[ 7,  9],
       [19, 21]])
```

In the above example, `1:5:2` is a slice notation, and `slice(1, 5, 2)` is a slice object.
Both have the same mean: from 1 to 4 with step 2.

I want to write the same thing in Ruby, but the current Ruby doesn't have any notations for slice.

While I tried to use `:` symbol in Ruby as Python, but it failed because `::` has the specific role.

Introducing step attribute in Range, we can get the value of step of a Range in a formal way, and we can write sliced views as following:

```ruby
ary[(1..4).step(2), (1..4).step(2)]
```

----------------------------------------
Feature #14044: Introduce a new attribute `step` in Range
https://bugs.ruby-lang.org/issues/14044#change-67717

* Author: mrkn (Kenta Murata)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
As described in #13904, Numo::NArray and PyCall touches internal structure of Enumerator to obtain the argument of `Range#step`.
**This information is necessary to realize the same manner of the utilization of Python's slices**.

In this ticket, I propose to introduce the new attribute `step` in an instance of `Range` class.
Its role is same as the `step` attribute of Python's slice.

`Range#step` should be changed to return a new Range object with the given step value instead of an Enumerator.
The default value of `step` attribute is `nil`, and it means that step is 1.





-- 
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>