[DOC] Tweaks for Array#[]
This commit is contained in:
parent
d657205c58
commit
b9a9564c1f
Notes:
git
2024-08-08 20:08:34 +00:00
3
array.c
3
array.c
@ -1759,12 +1759,15 @@ static VALUE rb_ary_aref2(VALUE ary, VALUE b, VALUE e);
|
||||
* In brief:
|
||||
*
|
||||
* a = [:foo, 'bar', 2]
|
||||
*
|
||||
* # Single argument index: returns one element.
|
||||
* a[0] # => :foo # Zero-based index.
|
||||
* a[-1] # => 2 # Negative index counts backwards from end.
|
||||
*
|
||||
* # Arguments start and length: returns an array.
|
||||
* a[1, 2] # => ["bar", 2]
|
||||
* a[-2, 2] # => ["bar", 2] # Negative start counts backwards from end.
|
||||
*
|
||||
* # Single argument range: returns an array.
|
||||
* a[0..1] # => [:foo, "bar"]
|
||||
* a[0..-2] # => [:foo, "bar"] # Negative range-begin counts backwards from end.
|
||||
|
Loading…
x
Reference in New Issue
Block a user