Is it possible from a class to grab the name of the object instance?

Hello all rubyist,

I fall in love of ruby some years ago when I reach to re-write in a
couple of days with ruby only a scripts I spent some
weeks to write with classical unix tools (awk, sed, grep, …) and the
new stuff was running far more quickly.

To learn more ruby, I tried also to write a script to build the linux
toolchain (i.e. binutils, glibc, gcc).
As far as for those tools the build sequence is the same (cleanup a
previous build, configure, make, install), it was easy
to design a class which I named TCModule to run each of those steps for
each module (binutils, glibc, gcc).

When something went wrong some where, I like to log outputs produced by
each method in a file.
Idealy, this file should have a name with the module name (e.g.
binutils) and the on going step, typically the method name.

Till now, to create this log file name, I didn’t find better way to
create variabales to own to those values like:

[snip]

Class of ToolChain Module: binutils|gcc|glibc

class TCModule
# make accessible object variables
attr_accessor :ModuleName, :Target, :Host, :Config, :Prefix,
:XcPath,
:Install, :Env, :Extra
attr :CurrentMethod

 # methode called by new to initialise object variables
 def initialize(_ModuleName, _Target, _Host, _SpecConfig, _Prefix, 

_XcPath,
_Install, _Env, _Extra)
@ModuleName = _ModuleName # name of module to
build
[snip]
@CurrentMethod = nil # On going action name
@LogPrefx = “#{$LogDir}/#{@ModuleName}#{@Extra}-#{LaunchDate}”

 end # initialize

[snip]

 # configure
 def _Configure
     @CurrentMethod = "_Configure"

[snip]
end # _Configure

 # install
 def _Install
     @CurrentMethod = "_Install"

     return make("#{@CurrentMethod}", "install")
 end # _Install

end # class TCModule

[snip]

which is initialized like:
_Binutils = TCModule.new(:_Binutils.id2name, # ModuleName: name of
module to build
Target, # Target: target we’re
building for
LocalMach, # Host: compiler to
use
$BinUtilsConfigP1, # Prefix: where to
install
$TempXC, # SpecConfig: Extra
config parameters
$TempXC, # XcPath: xcompiler
Path
“”, # Install:
“”, # Env: Extra env
parameters
“”) # Extra: Xtra release
info (pass1, 2)

But to make maintenance easiest, isn’t it possible in the methods to
grab the name of the object (instance) (my ModuleName)
for which it’s on going to run?

Tx in advance for ideas,
r.

2008/5/18, rubisher [email protected]:

But to make maintenance easiest, isn’t it possible in the methods to grab
the name of the object (instance) (my ModuleName) for which it’s on going to
run?

I remember asking if it’s possible to get a variable name using any
variable method and the answer was “no”. So I assume the same for
objects since basically are the same.

self.class.to_s should work

a class which I named TCModule to run each of those steps for
each module (binutils, glibc, gcc).

Is your code available somewhere? Especially the above quoted part
spiked my interest, as I was not aware one could decouple an
autoconfigured, running build-way (with or in ruby).

Iñaki Baz C. wrote:

2008/5/18, rubisher [email protected]:

But to make maintenance easiest, isn’t it possible in the methods to grab
the name of the object (instance) (my ModuleName) for which it’s on going to
run?

I remember asking if it’s possible to get a variable name using any
variable method and the answer was “no”.
Yes I remember vaguely to have read something like this some where
(obvioulsy no means to find back when you want).
I also had the filling it was already sometime ago, so in the mean time
it could be possible this changed in the
implementation of ruby (I was to busy this last week to order the 3rd
Edition of “Programming Ruby” but I will do asap :wink:

So I assume the same for
objects since basically are the same.

Tx for feedback,
r.