0

I have a method that I would like to pass in a number of arguments for and then create a number of arrays based on how many arguments are passed in.

def method(*args)
  number_of_arrays = args.count
  for i in 1..number_of_args
    # create arrays
  end
  args.map do |arg|
      # do something and add to an array
  end
  # I should now have a number of different arrays based on how many arguments are passed in
  # do something with those arrays
end

Any guidance?

1 Answer 1

2
def method(*args)
  arrays = Array.new(args.count) { [] }

  args.each_with_index do |arg, index|
      arrays[index] << # add some form of the arg to each array
  end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.