On Tue, May 24, 2011 at 3:50 PM, Andreas Lundgren
<andreas.lundgren.x / gmail.com> wrote:
>> > First params typically assembles to this:
>> > x1.to_s + ', ' + x2.to_s + ', ' + x3.to_s + ', ' + x4.to_s
>>
>> That does not look good. =A0If you have to encode numbers in variable
>> names, you probably rather want to use an Array for that or even
>> generate that directly:
>>
>> params =3D no_of_params.times.map {|i| "x#{i}"}.join(', ')
>
> your example generates code looks like this:
> params =3D x1, x2, x3, x4
> But with that I get an error (eval):3:in `+': can't convert Fixnum
> into String (TypeError)

Without the code you are executing that error is pretty useless.

It works for me:

irb(main):023:0> STUB_CALLS=3Dfalse
(irb):23: warning: already initialized constant STUB_CALLS
=3D> false
irb(main):024:0> GET_VALUE "f", "m", "r", 4
def f(x0, x1, x2, x3)

     oai =3D OA.instance
     handle =3D oai.getWIN32OLEHandle()
     handle.call(['MethodNameIn','Params'],['m', [x0, x1, x2, x3]]);
     ret_val =3D handle.GetControlValue(r);
     error =3D handle.GetControlValue('error out');
     return oai.checkForError(error) ? 'NaN': ret_val

end
=3D> nil
irb(main):025:0> STUB_CALLS=3Dtrue
(irb):25: warning: already initialized constant STUB_CALLS
=3D> true
irb(main):026:0> GET_VALUE "f", "m", "r", 4
def f(x0, x1, x2, x3)
printf("Calling m(x0, x1, x2, x3) with parameters <%p>\n", [x0, x1, x2, x3]=
)
end
=3D> nil
irb(main):027:0>

(with my definition of GET_VALUE from earlier)

>> params_2 =3D "#{x1}, #{x2}, #{x3}, #{x4}"
> Yes, I could use this, but still I need to assembly this line since I
> dont know the number of input parameters at coding time. And I know
> that no input parameters contain any expressions that needs to be
> evaluated since it is an input from my generated function.

I find the solution with printf "%p" and the Array more elegant.

Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/