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 9139827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:26:16+00:00 2026-06-17T09:26:16+00:00

I have a method that looks like def SomeMethod (*args) m = if args.length

  • 0

I have a method that looks like

def SomeMethod (*args)
     m = if args.length > 0 then 
            self.method(:method1) 
         else 
            self.method(:method2)
         end
     m.call ... #need to either pipe all arguments aside from the first
                #and in other cases substitute the first argument
end

The actual structure is a litle more complex where the method to be called is from different instances and in some cases I’d have to pipe all arguments lest the first and in other cases I’d have to substitute the first argument with another value

  • 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-17T09:26:17+00:00Added an answer on June 17, 2026 at 9:26 am

    You can use the so called splat operator * to expand an array into an argument list:

    # Call with all but the first element
    m.call *args[1..-1]
    
    # Replace first element
    m.call *args[1..-1].unshift(newarg)
    

    What does the (unary) * operator do in this Ruby code?
    Weird multiplicator operator behavior in a two arrays to hash combination

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

Sidebar

Related Questions

For example I have a method that looks like this [self performSelectorOnMainThread:@selector(someMethod) withObject:data waitUntilDone:YES];
i have a method in a model that looks like this: def self.super_data self.find(:all,
I have code that looks like this: Class Parent: def someMethod(self): return 42 Class
Let's say that I have a method that looks like this: def raise_if_client_status_error(xml_resp) #
I have an age method on my Waiver model that looks like: def age(date
I have a help method that looks a something like this: def html_format(text, width=15,
I have a MainWindow that looks like this: def __init__(self, parent = None): QMainWindow.__init__(self,
I have a method that looks like the following in my controller: def some_request
I have an awesome little function that looks like this: def verbose_print(message, *args, **kwargs):
I have a method that looks like this: public static String escape(String text) {

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.