Method with variables


#1

I define metod:

def dodaj_fronty(instancja,typ_szafki,korpus_szer,korpus_wys,korpus_gleb=56,program,front_gierunek,front_wys,front_szer,front_kolor,przest_ile=0,agd_wys=60,czy_panel="No",kierunek="Left")
...
end

And receive an error:

Error: #<SyntaxError: : syntax error, unexpected ‘=’, expecting ‘)’
…nt_szer,front_kolor,przest_ile=0,agd_wys=60,czy_panel=“No”,k…
… ^>
SketchUp:1:in `eval’

Do you have any idea, why?


#2

You may need to put all the optional parameters at the end of the list.

For methods with many parameters , using an options Hash may be better.


#3

Yes, for SketchUp 2013 and earlier using old version of Ruby 1.8.x.

This was changed before Ruby 2.x (sometime) and now the default values can appear anywhere in the argument list.