From: Morton Goldberg Date: 2006-07-24T05:33:16+09:00 Subject: Re: get caller of method Although others may suggest fancier techniques, I suggest a very simple approach -- just have the caller identify itself. For example: #! /usr/bin/ruby -w class Foo def connect @server = Server.new @server.connect(self) end end class Bar < Foo end class Server def connect(sender) @client = sender puts @client.class.name end end Foo.new.connect Bar.new.connect # --- end of code ---- Regards, Morton On Jul 23, 2006, at 3:06 PM, thomas coopman wrote: > Hi, > > Does there exist a method to get the object or type of object that > calls this method? > > for example: > > class Foo > do > end > class Bar > do > end > > do > if caller.kind_of?(Foo) > puts "Foo" > elsif caller.kind_of?(Bar) > puts "Bar" > end > end