From: Rick DeNatale Date: 2009-02-13T02:56:25+09:00 Subject: Re: * before string --00163646d97f570e850462bc75a4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On Thu, Feb 12, 2009 at 12:22 PM, Bertram Scharpf wrote: > Hi, > > Am Freitag, 13. Feb 2009, 01:51:24 +0900 schrieb Jonatas Paganini: > > class NamedArg > > def initialize(s) > > @name, @type = *s.split(':') > > end > > end > > > > Why and where use * before string? > > Actually, you use the asterisk in front of an array. The asterisk > makes the array to a list of arguments. Examples: > > ary.push [ :a, :b] # pushes an array > ary.push *[ :a, :b] # pushes two symbols > > You may even do this: > > done = %(exit quit bye) > case str.downcase > when *done then return > end > > In your example, the conversion will be done automatically when > the right side is an array. When I code, I write the asterisk > explicitly every time to remind myself what I meant. All true, except that in this case, it's in the context of a parallel assignment statement rather than a method call. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale --00163646d97f570e850462bc75a4--