view 1-Ruby/arrays-ruby.output @ 103:98be775c533c default tip

An odd "non-determinism" example from StackOverflow It is clever, but doesn't make much sense as to how it gets its results
author IBBoard <dev@ibboard.co.uk>
date Sun, 14 Jul 2019 13:44:13 +0100
parents 9aa1eba404f0
children
line wrap: on
line source

lions
tigers
bears
Accessing undefined indexes gives nil
Negative indexes also work (like Python): -1 =  bears
And you get slices/ranges: 1..2 = ["tigers", "bears"]
1..2 is even an object: Range
and indexers are methods: [1].methods.include?(:[]) = true
as is assignment to an array! [1].methods.include?(:[]=) = true

All funky non-ASCII methods for arrays:
==
[]
[]=
<<
<=>
+
*
-
&
|
===
=~
!~
!
!=

Arrays are also stacks with push() and pop() methods!