Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3615362
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:21:51+00:00 2026-05-18T22:21:51+00:00

I have a method that accepts the splat operator: def hello(foo, *bar) #… do

  • 0

I have a method that accepts the splat operator:

def hello(foo, *bar)   
   #... do some stuff 
end

I have an array with a variable length that I’d like to send into this hello method:

arr1 = ['baz', 'stuff']
arr2 = ['ding', 'dong', 'dang']

I’d like to call the method with arr1 and arr2 as arguments to that method but I keep getting hung up in that *bar is being interpreted as an array instead of individual arguments. To make things more fun, I can’t change the hello method at all.

I’m looking for something similar to this SO question but in ruby.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:21:51+00:00Added an answer on May 18, 2026 at 10:21 pm

    try calling it like this

    hello(arr1, *arr2)
    

    here’s a run through in irb

    irb(main):002:0> def hello(foo, *bar)
    irb(main):003:1>   puts foo.inspect
    irb(main):004:1>   puts bar.inspect
    irb(main):005:1> end
    => nil
    irb(main):006:0> arr1 = ['baz', 'stuff']
    => ["baz", "stuff"]
    irb(main):007:0> arr2 = ['ding', 'dong', 'dang']
    => ["ding", "dong", "dang"]
    irb(main):008:0> hello(arr1, arr2)
    ["baz", "stuff"]
    [["ding", "dong", "dang"]]
    => nil
    irb(main):009:0> hello(arr1, *arr2)
    ["baz", "stuff"]
    ["ding", "dong", "dang"]
    => nil
    

    by adding the * to the second array, it treats them as an array instead of an array of an array, which is what you’re looking for i think

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method in my business logic layer that accepts a stream, which
I have a method that needs to accept an array of country names, and
I have a method that accepts a bunch of strings in seperate parameters public
I have a method that accepts an IEnumerable-decimals and performance various math functions. I
I have a method that accepts a sender and is called with a UIbutton.
I have written a method that accepts a TextWriter as an argument (Usually Console.Out,
Like java, I want to create a method that accepts an array list of
I have class method that returns a list of employees that I can iterate
I have a method that where I want to redirect the user back to
I have a method that can return either a single object or a collection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.