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

R

rubisher

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.
 
I

Iñaki Baz Castillo

MjAwOC81LzE4LCBydWJpc2hlciA8cnViaXNoZXJAc2NhcmxldC5iZT46Cgo+ICBCdXQgdG8gbWFr
ZSBtYWludGVuYW5jZSBlYXNpZXN0LCBpc24ndCBpdCBwb3NzaWJsZSBpbiB0aGUgbWV0aG9kcyB0
byBncmFiCj4gdGhlIG5hbWUgb2YgdGhlIG9iamVjdCAoaW5zdGFuY2UpIChteSBNb2R1bGVOYW1l
KSBmb3Igd2hpY2ggaXQncyBvbiBnb2luZyB0bwo+IHJ1bj8KCkkgcmVtZW1iZXIgYXNraW5nIGlm
IGl0J3MgcG9zc2libGUgdG8gZ2V0IGEgdmFyaWFibGUgbmFtZSB1c2luZyBhbnkKdmFyaWFibGUg
bWV0aG9kIGFuZCB0aGUgYW5zd2VyIHdhcyAibm8iLiBTbyBJIGFzc3VtZSB0aGUgc2FtZSBmb3IK
b2JqZWN0cyBzaW5jZSBiYXNpY2FsbHkgYXJlIHRoZSBzYW1lLgoKLS0gCknDsWFraSBCYXogQ2Fz
dGlsbG8KPGliY0BhbGlheC5uZXQ+Cg==
 
R

rubisher

Iñaki Baz Castillo said:
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 ;-)
So I assume the same for
objects since basically are the same.
Tx for feedback,
r.
 
M

Marc Heiler

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top