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.  ¨Âùïèáöå ôï åîãïäå îõíâåòéî öáòéáâìå
>> names, you probably rather want to use an Array for that or even
>> generate that directly:
>>
>> params = no_of_params.times.map {|i| "x#{i}"}.join(', ')
>
> your example generates code looks like this:
> params = 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=false
(irb):23: warning: already initialized constant STUB_CALLS
=> false
irb(main):024:0> GET_VALUE "f", "m", "r", 4
def f(x0, x1, x2, x3)

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

end
=> nil
irb(main):025:0> STUB_CALLS=true
(irb):25: warning: already initialized constant STUB_CALLS
=> 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
=> nil
irb(main):027:0>

(with my definition of GET_VALUE from earlier)

>> params_2 = "#{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

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