From: Florian Gross Date: 2005-01-22T00:45:57+09:00 Subject: Re: Refernce objects Richard Turner wrote: > Fair enough :) I'd shy away from it because to me (at least, at the > moment), it seems to imply enumeration. I'd be tempted to assume that > Section[] would 'fill' from index 0 so that, if there are any Sections, > there will certainly be Section[0]. Since the parameter is an ID, not > an index, it doesn't seem right. > > On the other hand, Section{} sits fine in my head, since there's no > implied order there :) But we use the #[] method for both Hash, Array and Function access: hash = { 1 => 2 } hash[1] ary = [1, 2] ary[1] fun = lambda { |x| x * 2 } fun[2] # mixture between lambda and hash. Nifty way for doing cached lambdas. factorial = Hash.new do |hash, key| hash[key] = case when key == 1: 1 when key < 1: 0 else hash[key - 1] * key end end factorial[500]