[#50466] [ruby-trunk - Bug #7492][Open] Segmentation fault at DL::TestDL#test_call_double on x64 Windows 8 — "phasis68 (Heesob Park)" <phasis@...>

23 messages 2012/12/02

[#50558] [ruby-trunk - Feature #7511][Open] short-circuiting logical implication operator — "rits (First Last)" <redmine@...>

12 messages 2012/12/04

[#50575] [ruby-trunk - Feature #7517][Open] Fixnum::MIN,MAX — "matz (Yukihiro Matsumoto)" <matz@...>

20 messages 2012/12/05

[#50755] Becoming a committer — Charlie Somerville <charlie@...>

Hi ruby-core,

21 messages 2012/12/11
[#50759] Re: Becoming a committer — Yukihiro Matsumoto <matz@...> 2012/12/11

Hi,

[#50784] Re: Becoming a committer — Charles Oliver Nutter <headius@...> 2012/12/11

It's really this easy? If so, I'll send over my public key today :)

[#50795] Re: Becoming a committer — Yukihiro Matsumoto <matz@...> 2012/12/11

Hi,

[#50806] [ruby-trunk - Feature #7548][Open] Load and Require Callbacks — "trans (Thomas Sawyer)" <transfire@...>

12 messages 2012/12/12

[#50810] [ruby-trunk - Feature #7549][Open] A Ruby Design Process — "brixen (Brian Ford)" <brixen@...>

34 messages 2012/12/12

[#50867] [ruby-trunk - Bug #7556][Assigned] test error on refinement — "usa (Usaku NAKAMURA)" <usa@...>

14 messages 2012/12/13

[#50900] [ruby-trunk - Bug #7564][Open] r38175 introduces incompatibility — "tenderlovemaking (Aaron Patterson)" <aaron@...>

14 messages 2012/12/14

[#50951] [ruby-trunk - Bug #7584][Open] Ruby hangs when shutting down an ssl connection in gc finalization — "bpot (Bob Potter)" <bobby.potter@...>

12 messages 2012/12/17

[#51076] [ruby-trunk - Feature #7604][Open] Make === comparison operator ability to delegate comparison to an argument — "prijutme4ty (Ilya Vorontsov)" <prijutme4ty@...>

12 messages 2012/12/22

[#51170] [ruby-trunk - Bug #7629][Open] Segmentation fault — "atd (Antonio Tapiador)" <atapiador@...>

13 messages 2012/12/28

[ruby-core:50783] [ruby-trunk - Feature #4541] Inconsistent Array.slice()

From: "stomar (Marcus Stollsteimer)" <redmine@...>
Date: 2012-12-11 19:42:24 UTC
List: ruby-core #50783
Issue #4541 has been updated by stomar (Marcus Stollsteimer).


Regarding the OP's criticism of poor API documentation, this has in the meantime been improved (with issue #6680).

From the current documentation for Array#slice:

  Negative indices count backward from the end of the array (-1 is the last
  element).  For +start+ and +range+ cases the starting index is just before
  an element.  Additionally, an empty array is returned when the starting
  index for an element range is at the end of the array.

  Returns +nil+ if the index (or starting index) are out of range.

  a = [ "a", "b", "c", "d", "e" ]
  a[2] +  a[0] + a[1]    #=> "cab"
  a[6]                   #=> nil
  a[1, 2]                #=> [ "b", "c" ]
  a[1..3]                #=> [ "b", "c", "d" ]
  a[4..7]                #=> [ "e" ]
  a[6..10]               #=> nil
  a[-3, 3]               #=> [ "c", "d", "e" ]
  # special cases
  a[5]                   #=> nil
  a[6, 1]                #=> nil
  a[5, 1]                #=> []
  a[5..10]               #=> []
----------------------------------------
Feature #4541: Inconsistent Array.slice()
https://bugs.ruby-lang.org/issues/4541#change-34633

Author: kbl (Marcin Pietraszek)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
Array slice/[] method is a bit inconsistent. Is it just poorly documented "feature" or a bug? In API doc I can't find this behaviour mentioned as a "special case".

 def test_array_slice
    array = ['a', 'b', 'c']
    assert_equal nil, array[3]
    assert_eaual nil, array[4]
 
    assert_eaual [], array[3, 0] #
    assert_equal nil, array[4, 0] # [] expected (or both nils in array[3, 0] and array[4, 0])
 
    assert_equal ['c'], array[2..2]
    assert_equal [], array[3..3] #
    assert_equal nil, array[4..4] # [] expected (or both nils in array[3..3] and array[4..4])
 end

Same behaviour can be reproduced on ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux].
=end



-- 
http://bugs.ruby-lang.org/

In This Thread

Prev Next