Matthew J.son wrote:
Thank you, guys
Although it’s not what I wanted, I have a lot of ideas in some
directions. It’s good for new in Ruby.
Henry
Can you describe some of your ideas? That would certainly help
foster discussion…
Matthew
There is nothiing new. It’s as old as Univac
What I want is a classic Macroprocessor tool.
I mean:
I keep pieces of souce code in some place.
They may be included in source code as is. More interesting, you can
adjust macroprocessor’s output (hence, the input for Ruby interpeter)
using paremters.
E X A M P L E:
You wrote the macro once and put it in macro library
(here I “invented” the “macrolanguage” on-fly, while writing the
example. I hope, the “language” is clear)
====this is a macro %var with argument %%x definition==============
macro: %var (%%x)
{def %%x=(value)
@%%x = value
return @%%x
end}
======== end of macro %var definition =============================
You may consider the macro definition as a template.
Now, somewhere in your code you write:
…
%var(my_lovely_var)
…
Once found the %var, macroprocessor should make substitutions and
produce this piece:
def my_lovely_var=(value)
@my_lovely_var = value
return @my_lovely_var
end
which will be inserted into code on the place, where the statement
%var(my_lovely_var) was instead of it.
Ruby style allows to expect, that it may be done on-fly.
So, finally the Ruby interpreter will execute the macroprocessor’s
output, not input. Besides the macroprocessor’s input and output are
saved, so you can return to them and change the simple lines of
get/set-code to something more complicated and valueable.
Again the get/set operations are just an EXAMPLE, used because everyone
is familiar with this piece of code. Sure, using attributes is kind of
solution for this particular case. (BTW. Thank you, Farrel L., you
post convinced me to learn more about attributes on this very beginning
stage, and that was very usefull). I want the macro power options
themselves.
Sure, every language may consider any code as an input string, and
process the string, (and Ruby itself is a great for these purposes), but
macroprocessor is something very specialized for swiftness and
convinience, to do particular job of entering the code. Ruby’s
macroprocessor tool may be specialized for entering Ruby code, which
would make it more powerful.
There are plenty of editors with comprehensive macro functions. But they
are OS dependent. As Ruby is claimed to be system independent, I would
prefer to have Ruby’s own macroprocessor, built for Ruby in mind.
More I am writing on this topic, more I am thinking, that a highly
customized for Ruby editor with macro functions would be the solution…