From: Mark Slagell Date: 2000-12-21T06:17:47+09:00 Subject: [ruby-talk:7795] Re: Regex array subscripts craig duncan wrote: > > I'm just a Ruby-nuby and sparse documentation has me trying to construct > my own (deeper) explanations for why things work the way they do. wrt: > > "one 123 two"[/\d+/] => "123" > > even more simply we have: > > "one 123 two"['e 1'] => "e 1" > > So, what is confusing is when the documentation says: > > "Arrays are ordered, integer-indexed collections of any object." > > It appears that an integer index is only one way of accessing array > elements. Which is what had me confused, because i was led to think > that /\d/ and /\d+/ both return an (the same) integer. But apparently > they return the matched string, which works just fine as an array > index. Wierd. A regexp doesn't "return" an integer in the way you seem to be saying, but is an argument that String's square-brackets method understands. This behavior is documented, so maybe a "deeper" explanation is not needed. :-) see http://dev.rubycentral.com/ref/ref_c_string.html#_ob_cb Also - maybe I'm misunderstanding you, but although arrays and strings share some characteristics, they are not the same type. -- Mark