From: 7stud -- Date: 2009-09-16T05:21:29+09:00 Subject: Re: .map.with_object(3){|v|v+3} #=> 3 Is this a bug? David A. Black wrote: > Hi -- > > On Wed, 16 Sep 2009, 7stud -- wrote: > >>>> ------------------------------------------------------------------------ >>> tens_hash = array.each_with_object({}) {|n,obj| obj[n] = n * 10 } >>> call on it: >>>> >> 2) Why (*args) ? > I read it as just shorthand for "miscellaneous other arguments". I > don't know whether there's a better way to denote that. > When I see *args as a parameter variable, I expect the parameter variable to always reference an array. For instance: def meth(*args) p args end meth(1, 2) meth("red") --output:-- [1, 2] ["red"] So the *args confuses me in the ri info: ------------------------------------------------- Enumerator#with_object e.with_object(obj) {|(*args), memo_obj| ... } e.with_object(obj) From Ruby 1.9.1 -------------- As my examples show, sometimes args will be an array and other times it won't. >> In the definition: >> >>> e.with_object(obj) {|(*args), memo_obj| ... } >> >> 3) Why 'memo_obj' and not 'obj'? >> >> Even though two different variable names makes it hard to track what is >> going on, the following assignment takes place: >> >> memo_obj = obj > > I think it's schematic. obj is not necessarily the variable "obj"; > it's just an object: > I see. -- Posted via http://www.ruby-forum.com/.