From: Giles Bowkett Date: 2006-05-16T05:43:46+09:00 Subject: Re: Struct.new vs class On 5/15/06, Austin Ziegler wrote: > On 5/15/06, Giles Bowkett wrote: > > is "*a" basically a keyword args flag that tells initialize() to take > > any and all args and just pass them up the chain to super()? > > Except that it isn't keyword args. I like David Black's name for it: > the (un)array operator. I might have been thinking of a Python term... > It's an unary non-overridable operator on > arrays. When used on an array as a receiver, it indicates that it will > take a list of items and treat them as an array; when used on a sender > array, it splits that array out into a list: > > >> a = %w(a b c d e) > => ["a", "b", "c", "d", "e"] > >> b, c, *d = *a > => ["a", "b", "c", "d", "e"] > >> p a, b, c, d > ["a", "b", "c", "d", "e"] # a > "a" # b > "b" # c > ["c", "d", "e"] # d so when you feed it to initialize() like that, it translates the list it's been given into an array and then initialize() picks that up and says "oh, ok, this is the sequence of args I'm expecting"? and you could also do def initialize (*arbitrarily_long_name) end ? -- Giles Bowkett http://www.gilesgoatboy.org