From: Robert Klemme Date: 2008-05-21T18:33:01+09:00 Subject: Re: Is it possible from a class to grab the name of the object instance? 2008/5/20 rubisher : > Hello Marcin, > >> self.class.to_s should work >> >> > Sorry this return me the class name itself not the instance name? > > e.g. > #!/usr/bin/env ruby > > class Investment > def initialize > puts "I'am ALIVE!" > iname=self.class.to_s > puts "Instance Name: #{iname}" > end > end > > _Invest = Investment.new > > puts _Invest.class > > give me: > I'am ALIVE! > Instance Name: Investment > Investment > > and not "Instance Name: _Invest" as am looking for. There is no such thing as an instance name - unless you define a property of your class called "name". Each instance can be referenced by any number of variables including 0 - there is simply not _the_ name. As Inaki pointed out. Kind regards robert -- use.inject do |as, often| as.you_can - without end