I graduated in 1990 in Electrical Engineering and since then I have been in university, doing research in the field of DSP. To me programming is more a tool than a job.
Another curiosity is around the number of parameters passed to yield, which in turn are sent as block parameters to your block. Are they enforced/requested by Ruby or not? Give it a try using irb - you'll be surprised with the result!
Interesting, I never tried before (although I used Ruby fairly a lot). This also is interesting
I graduated in 1990 in Electrical Engineering and since then I have been in university, doing research in the field of DSP. To me programming is more a tool than a job.
It works also the other way around, as the varargin in Matlab. For example, suppose I define
deffoo(a,b,*c)pc;end
Here foo is a function that expects a number of arguments larger or equal than two. The first two arguments are assigned to a and b and all the remaining arguments (zero or more) are collected in an Array assigned to c. For example, if I call
Interesting, I never tried before (although I used Ruby fairly a lot). This also is interesting
Hi Riccardo,
Thanks for sharing! I couldn't understand how it works though. Would you mind explaining what is happening behind the scenes? =)
I thought the * (splat operator) was only used to "spread" elements of a collection when passing it as an argument to a function.
It works also the other way around, as the
varargin
in Matlab. For example, suppose I defineHere
foo
is a function that expects a number of arguments larger or equal than two. The first two arguments are assigned toa
andb
and all the remaining arguments (zero or more) are collected in anArray
assigned toc
. For example, if I callthe function prints
["x", nil, 12]
, if I callthe function prints
[ ]
, if I callI get an error
Hi Riccardo,
Thank you for taking to explain it - it is more clear to me now how it works!