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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:58:01+00:00 2026-05-29T09:58:01+00:00

New to Ruby and ROR and loving it each day, so here is my

  • 0

New to Ruby and ROR and loving it each day, so here is my question since I have not idea how to google it (and I have tried 🙂 )

we have method

def foo(first_name, last_name, age, sex, is_plumber)
    # some code
    # error happens here
    logger.error "Method has failed, here are all method arguments #{SOMETHING}"    
end

So what I am looking for way to get all arguments passed to method, without listing each one. Since this is Ruby I assume there is a way 🙂 if it was java I would just list them 🙂

Output would be:

Method has failed, here are all method arguments {"Mario", "Super", 40, true, true}
  • 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-29T09:58:02+00:00Added an answer on May 29, 2026 at 9:58 am

    In Ruby 1.9.2 and later you can use the parameters method on a method to get the list of parameters for that method. This will return a list of pairs indicating the name of the parameter and whether it is required.

    e.g.

    If you do

    def foo(x, y)
    end
    

    then

    method(:foo).parameters # => [[:req, :x], [:req, :y]]
    

    You can use the special variable __method__ to get the name of the current method. So within a method the names of its parameters can be obtained via

    args = method(__method__).parameters.map { |arg| arg[1].to_s }
    

    You could then display the name and value of each parameter with

    logger.error "Method failed with " + args.map { |arg| "#{arg} = #{eval arg}" }.join(', ')
    

    Note: since this answer was originally written, in current versions of Ruby eval can no longer be called with a symbol. To address this, an explicit to_s has been added when building the list of parameter names i.e. parameters.map { |arg| arg[1].to_s }

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

Sidebar

Related Questions

new to ruby, and rails... but not to the amp stack. my preferred method
I am a new to Ruby on Rails and I have a question on
I am new to Ruby on Rails, I have completed the Blog Tutorial .
I an new in ruby and rails. Following the guide in ror document,I create
Im new to RoR/Ruby and i cant seem to get the simplest thing to
i am new to ROR, just setup the enviroment ruby 1.9.2 with rails 3.0.6
Just starting to learn Ruby on Rails. I'm using RoR 3. I have read
I am new to Ruby on Rails, Now try to install ROR. I follow
I am new to ROR. I am using Ruby 1.9.2p290, rvm 1.10.2, chromedriver version=18.0.995.0.
I am very new to RoR... I installed Ruby and installed its gems... then

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.