Is there a way to convert an array to a (parameter-)list?
I often find myself doing things like:
year,mon,day,hour,minute = ParseDate.parse(datestring)
printf("%04d-%02d-%02d %02d:%02d\n",year,mon,day,hour,minute)
while it would be a lot nicer to do:
printf("%04d-%02d-%02d %02d:%02d\n", ParseDate.parse(datestring)
It is of course perfectly possible to redefine printf and make it check
whether it is offered an array or a parameter list, but it would be a lot
easier when ruby did so automatically.
Alternatively, there could be something like Array#flatten which flattens
an array to a list.
···
–
Wybo
just use a * just before an array to make it a list of parameters.
Btw, maybe you could just use
print Date.strftime(yourformat)
···
il Sat, 15 Nov 2003 21:23:09 +0900, Wybo Dekker wybo@servalys.nl ha scritto::
Is there a way to convert an array to a (parameter-)list?
I often find myself doing things like:
year,mon,day,hour,minute = ParseDate.parse(datestring)
printf(“%04d-%02d-%02d %02d:%02d\n”,year,mon,day,hour,minute)
while it would be a lot nicer to do:
printf(“%04d-%02d-%02d %02d:%02d\n”, ParseDate.parse(datestring)
Great! That’s just what I was looking for;
I now could even find it in the book; thanks!
···
On Sat, 15 Nov 2003, ts wrote:
ruby -rparsedate
-e ‘printf(“%04d-%02d-%02d %02d:%02d\n”,
*ParseDate.parsedate(Time.now.to_s))’
2003-11-15 13:31
–
Wybo