+
+ ##
+ # call-seq:
+ # ary[rng] -> ary slice
+ #
+ # Remeturns a slice of +ary+ according to the Range instance +rng+.
+ #
+ # a = [ "a", "b", "c", "d", "e" ]
+ # a[1] => "b"
+ # a[1,2] => ["b", "c"]
+ # a[1..-2] => ["b", "c", "d"]
+ #
+ def [](idx, len=nil)
+ case idx
+ when Range
+ if idx.last < 0 then
+ len = self.length - idx.first + idx.last + 1
+ else
+ len = idx.last - idx.first + 1
+ end
+ return self.slice(idx.first, len)
+ when Numeric
+ if len then
+ return self.slice(idx.to_i, len.to_i)
+ else
+ return self.slice(idx.to_i)
+ end
+ else
+ self.slice(idx)
+ end
+ end
+