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

  • Home
  • SEARCH
  • 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 9306869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:16:01+00:00 2026-06-19T00:16:01+00:00

Say I have an array. I wish to pass the array to a function.

  • 0

Say I have an array. I wish to pass the array to a function. The function, however, expects two arguments. Is there a way to on the fly convert the array into 2 arguments?
For example:

a = [0,1,2,3,4]
b = [2,3]
a.slice(b)

Would yield an error in Ruby. I need to input a.slice(b[0],b[1]) I am looking for something more elegant, as in a.slice(foo.bar(b))
Thanks.

  • 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-06-19T00:16:02+00:00Added an answer on June 19, 2026 at 12:16 am

    You can turn an Array into an argument list with the * (or “splat”) operator:

    a = [0, 1, 2, 3, 4] # => [0, 1, 2, 3, 4]
    b = [2, 3] # => [2, 3]
    a.slice(*b) # => [2, 3, 4]
    

    Reference:

    • Array to Arguments Conversion
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have an array of number a <- c(1,2,3,6,7,8,9,10,20) if there a way
Say you have an array, data, of unknown length. Is there a shorter method
say I have an array of objects with html strings inside (there are other
Let's say I have array like {12,23,,34,22,,,12} If there are 5 items as than
Say I have an array of Employee Objects: var Employee = function(fname, age) {
Let's say I have an array of jQuery objects and wish to have one
Say we have array of arrays: tree_limbs = Array.new tree_limbs << %w(1 2 3
Let's say I have array of bytes: byte[] arr = new byte[] { 0,
Say I have an array of table DDL queries and I want to get
Say I have an array of key/value pairs in PHP: array( 'foo' => 'bar',

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.