From: matt@... (matt neuburg) Date: 2009-06-06T10:50:11+09:00 Subject: Re: Can someone explain the difference: Array[] and Array.fetch Marc Heiler wrote: > array = ["a","b","c"] # => ["a", "b", "c"] > array[1] # => "b" > array.fetch 1 # => "b" > > > # ================================================== # > # So far, so fine. > # ================================================== # > > > array[666] # => nil > array.fetch 666 > > IndexError: index 666 out of array > from (irb):5:in `fetch' > from (irb):5 > > > This may seem like a trival difference between the two, but > I am wondering in general why they behave differently. > Or in other words, why array[] does not return an error > whereas .fetch specifically does. fetch is more general; if you want it to behave like []() in this case, say array.fetch(666,nil). m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Leopard - http://www.takecontrolbooks.com/leopard-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com