From: Brian Candler Date: 2008-12-12T17:42:43+09:00 Subject: Re: parallel method return value Louis-Philippe wrote: > and with a method: > >>> def a_method >>> return 1, 2, 3 >>> end This behaves identically to return [1, 2, 3] That is, a single array object is returned. AFAIK, methods always return exactly one value. > If I want only one lvalue, is this: >>> a, = 1, 2, 3 > => [1, 2, 3] >>> a > => 1 > the only way to get it? a = a_method is saying "assign whatever object is returned from a_method to a", and if that's an array, then an array is what you get. You can use the multiple-assignment syntax to drop the rest, or other Array operations like a = a_method[0] a = a_method.first > I would have liked for the return behaviour to be set on the right side, > to allow method invocation like: >>> puts a_method > > to return: > 1 > > instead of > 1 > 2 > 3 If a function returns an array, that's what I want to see; I wouldn't want it to be arbitarily munged. -- Posted via http://www.ruby-forum.com/.