Project

General

Profile

Actions

Feature #3653

closed

Diferential behaviour of positives and negatives ranges as subindex of string or arrays.

Added by dsilber (Daniel Silberschmidt) over 13 years ago. Updated over 6 years ago.

Status:
Rejected
Target version:
[ruby-core:31619]

Description

=begin
The expression '[a..b]' when applied to a string or to an array return the slice from the string/array from a to b.
for example [0..3] returns the first four letters from a string
irb(main):004:0> "carromato"[0..3]
=> "carr"
the slice [-4..-1] returns the last four letters from a string
irb(main):005:0> "carromato"[-4..-1]
=> "mato"
but if the length of the original string is smaller than the slice the results are conceptually very different depending on positive or negative indexes:
irb(main):006:0> "carromato"[0..24]
=> "carromato"
irb(main):007:0> "carromato"[-25..-1]
=> nil
I would like a simetric behaviour in the last case returning the whole word (and not nil). It would be more natural to have the same behaviour when exeding by left of by right of the string/array.
Does Anbody agree or disagree whith my position?
Daniel
=end

Actions #1

Updated by shyouhei (Shyouhei Urabe) over 13 years ago

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

=begin

=end

Updated by alexeymuranov (Alexey Muranov) over 12 years ago

I agree with this proposal. -Alexey.

Updated by mame (Yusuke Endoh) over 11 years ago

  • Description updated (diff)
  • Target version set to 2.6

Updated by matz (Yukihiro Matsumoto) over 6 years ago

  • Status changed from Assigned to Rejected

I don't think the change does not worth the potential incompatibility.

Matz.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0