From: Stefan Kanev Date: 2009-01-26T05:30:14+09:00 Subject: Re: How can I get the arguments passed to the caller. --001636499007be2820046154840e Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit So, suppose I want to get evil and go dig into frames and so on. I've seen ruby-debug do something close. Is there a part of the standard library that allows you to introspect that way (if so, I could not find it), or a gem maybe? And if not and I'm bend on writing C code to achieve it, where should I start looking? On Sun, Jan 25, 2009 at 9:39 PM, James Coglan wrote: > > I have a rather weird question. I want to write a function that > > programatically determines the arguments passed to its caller. Say, if i > do > > > > $stuff = [] > > > > def bar(arg) > > foo > > end > > > > def foo > > first_arg = .... > > $stuff << first_arg > > end > > > > bar(42) > > > > # By this point, $stuff would be [42] > > > > I think the closest you're going to get is for the calling function to pass > its binding so that foo can read from it: > > def bar(*args) > foo(binding) > end > => nil > def foo(env) > puts env.eval("args.first") > end > => nil > bar 'something' > something > > I don't think you can do this transparently. You can't even refer to the > argument list within a single method (I'm thinking of the 'arguments' > object > in JavaScript) without mentioning the arguments by name. > --001636499007be2820046154840e--