Assigning Arrays to different variables

I am having a simple requirement of Assigning Multiple arrays. Right now i am doing something like.

   employees = Array.new
      projects = Array.new
      practices = Array.new
      entities = Array.new
      categories = Array.new
      groups = Array.new
      external_inputs = Array.new
      payrolls = Array.new

I Want that employees, projects, practices, entities ...payrolls all should be assigned to Array.new in a single line Please suggest some better and clean ways of doing it. Maybe by Metaprogramming.

Answers


Ugly but fulfilling the requirements:

employees, projects, practices, entities, categories, groups, external_inputs, payrolls = Array.new(8) { [] }

employees, projects, practices, entities, categories, groups, external_inputs, payrolls = 
  8.times.map { [] }

I Want that employees, projects, practices, entities, …, payrolls all should be assigned to Array.new in a single line

Here ya go:

employees = Array.new; projects = Array.new; practices = Array.new; entities = Array.new; categories = Array.new; groups = Array.new; external_inputs = Array.new; payrolls = Array.new

Voilà, a single line, just as you requested.

Now, why you have such a large, complex method that it needs 8 local variables is another question altogether.


Need Your Help

Why are signed and unsigned multiplication different instructions on x86(-64)?

assembly x86 x86-64 twos-complement

I thought the whole point of 2's complement was that operations could be implemented the same way for signed and unsigned numbers. Wikipedia even specifically lists multiply as one of the operation...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.