From: Benjamin Oakes Date: 2008-03-19T23:35:06+09:00 Subject: Re: Inspetting a method's caller On Wed, Mar 19, 2008 at 9:10 AM, Alberto Santini wrote: > > but you can make the caller send in an extra argument, putting its > > description/ID/Name there. > > Of course i can, i just *don't want* to do this. For example, imagine i > want to access a database table that (by -> convention <-) has the same > name of a class. Imagine i have a DBHelper class that contains a > DBHelper#find method used to find records on the database. if > DBHelper#find is called from a Ball object i want to lookup on the > "ball" table, it it's called from a Cube object i want to search the > "cube" table, etc. This is just the simplest usage that came to my mind, > but i guess there are hundreds. Obviously, i can implement DBHelper#find > in a way like this: > > def find(table_name = "", criteria = {}) > ... > end > > and call it like this: > > find(self.class.to_s, {:id => 5}) > > It is just *not what i want to do*. > > So, coming back to my question, is there a simple way to get the wanted > class name, without haveing to parse Kernel#caller? > > Thanks. > -- > > > Posted via http://www.ruby-forum.com/. > > There's something in Ruby Facets that seems related: Binding#called http://facets.rubyforge.org/quick/rdoc/core/classes/Binding.html#M000221 I've only ever used it when I'm working with trace statements when a debugger isn't available or doing the job I need it to. -- Ben