# Extended information about a method's caller

**URL:** <https://rubytalk.org/t/extended-information-about-a-methods-caller/10527>\
**Category:** ruby-talk\
**Created:** [12 March 2004 04:09 UTC](https://rubytalk.org/t/extended-information-about-a-methods-caller/10527 "2004-03-12T04:09:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Atkins1](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@Bill\_Atkins1](https://rubytalk.org/u/Bill_Atkins1)\
**Post date:** [12 March 2004 04:09 UTC](https://rubytalk.org/t/extended-information-about-a-methods-caller/10527/1 "2004-03-12T04:09:32Z")

</div>

Is there any way to get a list of the arguments passed to a method’s caller? I am aware of Kernel.caller, but it seems like it just gives a method name. I would like something like this:

class Test  
def test1(x, y)  
test2  
end  
end

class Test2  
def test  
# here I’d like to have an Array containing two 2’s (the  
# values passed to Test.test1)  
end  
end

Test.new.test1(2, 2)

> **···**
>
> * * *
> 
> No banners. No pop-ups. No kidding.  
> Introducing My Way - [http://www.myway.com](http://www.myway.com)

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [13 March 2004 16:24 UTC](https://rubytalk.org/t/extended-information-about-a-methods-caller/10527/2 "2004-03-13T16:24:36Z")

</div>

“Bill Atkins” [batkins57@myway.com](mailto:batkins57@myway.com) schrieb im Newsbeitrag  
[news:20040312040924.AB9DF3977@mprdmxin.myway.com](mailto:news:20040312040924.AB9DF3977@mprdmxin.myway.com)…

> Is there any way to get a list of the arguments passed to a method’s  
> caller? I am aware of Kernel.caller, but it seems like it just gives a  
> method name. I would like something like this:
> 
> class Test  
> def test1(x, y)  
> test2  
> end  
> end
> 
> class Test2  
> def test  
> # here I’d like to have an Array containing two 2’s (the  
> # values passed to Test.test1)  
> end  
> end
> 
> Test.new.test1(2, 2)

If you know the argument names you might be able to hack something together  
with set\_trace\_func. But why don’t you just pass them on? 🙂

Regards

```
robert

```

---

<div class="post-metadata">

**Author:** ![Sabbyxtabby](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@Sabbyxtabby](https://rubytalk.org/u/Sabbyxtabby)\
**Post date:** [14 March 2004 11:29 UTC](https://rubytalk.org/t/extended-information-about-a-methods-caller/10527/3 "2004-03-14T11:29:35Z")

</div>

Or, if you hacked something together with set\_trace\_func, you might[1]  
be able to know the argument names. 🙂

module Kernel  
set\_trace\_func proc {|\*a|  
$bind = a[4] unless a[3] == :argument\_values  
}

```
def argument_values
  eval <<-'CODE', $bind
    caller(0)[0] =~ /`(.*)'/ or return
    $arity = method($1).arity
    $args = local_variables[0, $arity.abs]
    $args[-1] = '*' + $args[-1] if $arity < 0
    eval "[#{$args * ','}]"
  CODE
end

```

end

class Test  
def test(x, \*y)  
i = 0  
z = 0…9  
p argument\_values  
end  
end

Test.new.test(4, 5, 6)

[1] The ordering of local variables returned by local\_variables  
may be accidental.

> **···**
>
> “Robert Klemme” [bob.news@gmx.net](mailto:bob.news@gmx.net) wrote:
> 
> > “Bill Atkins” [batkins57@myway.com](mailto:batkins57@myway.com) schrieb im Newsbeitrag  
> > [news:20040312040924.AB9DF3977@mprdmxin.myway.com](mailto:news:20040312040924.AB9DF3977@mprdmxin.myway.com)…
> > 
> > > Is there any way to get a list of the arguments passed to a method’s  
> > > caller? I am aware of Kernel.caller, but it seems like it just gives a  
> > > method name.
> > 
> > If you know the argument names you might be able to hack something together  
> > with set\_trace\_func. But why don’t you just pass them on? 🙂
