Skip to content

Do something better with ranges and lengths #4

Description

@xunker

Array indexes can be ranges, or can be integers passed with a length.

Right now the gem handles these in the same way that the base Array class does:

[1,2,3][0..1]
# => [1,2]

[1,2,3][1,2]
# => [2,3]

That's all well and good, but they should do something... better. But what?

Ruby (2.0.0 at least) supports Ranges with Float boundaries. I'd like to see this:

[1,2,3,4][0.5..2.5]
# => [1.5, 2.5, 3.5]

%w[foo bar baz qux][0.5..2.5]
# => ["oob", "arb", "azq"]

That's easy. That's approach would also work verbatin with a length argument with the array index. But what about irregular ranges like [0.5..10.9]? What would the stepping be?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions