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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:07:30+00:00 2026-05-11T10:07:30+00:00

I would like to do some fairly heavy-duty reflection in Ruby. I want to

  • 0

I would like to do some fairly heavy-duty reflection in Ruby. I want to create a function that returns the names of the arguments of various calling functions higher up the call stack (just one higher would be enough but why stop there?). I could use Kernel.caller, go to the file and parse the argument list but that would be ugly and unreliable.

The function that I would like would work in the following way:

module A   def method1( tuti, fruity)      foo   end   def method2(bim, bam, boom)       foo   end   def foo     print caller_args[1].join(',') #the '1' mean one step up the call stack   end  end  A.method1  #prints 'tuti,fruity' A.method2  #prints 'bim, bam, boom' 

I would not mind using ParseTree or some similar tool for this task but looking at Parsetree, it is not obvious how to use it for this purpose. Creating a C extension like this is another possibility but it would be nice if someone had already done it for me.

I can see that I’ll probably need some kind of C extension. I suppose that means my question is what combination of C extension would work most easily. I don’t think caller+ParseTree would be enough by themselves.

As far as why I would like to do this goes, rather than saying ‘automatic debugging’, perhaps I should say that I would like to use this functionality to do automatic checking of the calling and return conditions of functions:

def add x, y    check_positive   return x + y end 

Where check_positive would throw an exception if x and y weren’t positive. Obviously, there would be more to it than that but hopefully this gives enough motivation.

  • 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. 2026-05-11T10:07:30+00:00Added an answer on May 11, 2026 at 10:07 am

    I suggest you take a look at Merb’s action-args library.

    require 'rubygems' require 'merb'  include GetArgs  def foo(bar, zed=42) end  method(:foo).get_args # => [[[:bar], [:zed, 42]], [:zed]] 

    If you don’t want to depend on Merb, you can choose and pick the best parts from the source code in github.

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If both pages are from the same domain (like you… May 11, 2026 at 11:04 am
  • added an answer There could be many reasons why but I am guessing… May 11, 2026 at 11:04 am
  • added an answer Found the right way of doing it. As the documentation… May 11, 2026 at 11:04 am

Related Questions

I would like to do some integration testing of a web service from within
I would like to write some scripts in python that do some automated changes
I would like to do something like the following: def add(a, b): #some code
I would like to load a BMP file, do some operations on it in
For some reasons, I would like to do an explicit quoting of a string
I would like to do full-text searching of data in my Ruby on Rails
I would like to do a lookup of tables in my SQL Server 2005
I would like to do something like <test:di id=someService /`> <% someService.methodCall(); %> where
I would like to do remote deployment from my build machine onto a server.
I would like to do something like the following but can't seem to get

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.