From: Robert Klemme Date: 2010-04-25T19:40:05+09:00 Subject: Re: Metaprogramming - Array initialization On 04/25/2010 12:35 AM, Rolf Pedersen wrote: > [Note: parts of this message were removed to make it a legal post.] > > A subtle improvement to the function, as I failed to remember that I could > expand an array to multiple arguments again when calling the function > recursively: > > def make_array(*a) > if a.size > 1 > Array.new(a.shift){make_array(*a)} > elsif a.size == 1 > Array.new(a.shift) > end > end And what about the case of an empty argument list? def make_array(*a) case a.size when 0 raise ArgumentError, "Need at least one dimension" when 1 Array.new(a.shift) else Array.new(a.shift){make_array(*a)} end end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/