From: Timothy Goddard Date: 2006-09-05T21:30:18+09:00 Subject: Re: Does an instance know his own name? You can identify an object by its object_id. Variables are just references to an object with a convenient name for your use. If you want to give an object an actual name, you have to pass it in as a parameter on construction. Geoff Barnes wrote: > If a class has built checks and raises an exception if it finds > something wrong, how can I tell which instance had the error? I know > there's an object_id, but can I know the name of the objects own > instance variable? > > huey = Nephew.new > duey = Nephew.new > luey = Nephew.new > > duey.raise_error_on_purpose_just_for_fun #-> "Nephew 'duey' raised an > error" > > Also, can an instance know his 'path' from the top-level? > > class Donald > > def initialize > @huey = Nephew.new > @duey = Nephew.new > @luey = Nephew.new > end > > end > > Donald1 = Donald.new > Donald2 = Donald.new > > Donald1.huey.raise_error_on_purpose_just_for_fun > #-> "Nephew Donald1.huey raised an error" > > Thanks, > > > > > > -- > Posted via http://www.ruby-forum.com/.