Ask a Question related to Ruby, Design and Development.
-
Wybo Dekker #1
array -> list
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
Wybo Dekker Guest
-
List from array .as
in this code ... the list is reading from Array ... but i can not display the name of each of them... ... if you click the button, and then... -
Creating a 2dm array from a list
I have a list of hrefs from three different sites which I have then stored into a 1dm array. There are around 40 elements (href's)in the 1dm array. ... -
list ($d, $row) = each ($array) by reference?
Hi ! I always thought that while (list($d,$row) = each($array)){ $row = 5; } would operate by reference, so that $array is filled with 5... -
[PHP] Array to List
All, Thanks for your help, but this shouldn't be so freaking hard to do. <sigh> 1) I have a multiple select input on one page that is populated... -
Array to List
Hello, Coming from ColdFusion, this is difficult. CF has an ArrayToList() function. I can't find anything similar in PHP. I'm building a list... -
ts #2
Re: array -> list
>>>>> "W" == Wybo Dekker <wybo@servalys.nl> writes:
W> printf("%04d-%02d-%02d %02d:%02d\n", ParseDate.parse(datestring)
svg% ruby -rparsedate \2003-11-15 13:31> -e 'printf("%04d-%02d-%02d %02d:%02d\n", *ParseDate.parsedate(Time.now.to_s))'
svg%
Guy Decoux
ts Guest
-
gabriele renzi #3
Re: array -> list
il Sat, 15 Nov 2003 21:23:09 +0900, Wybo Dekker <wybo@servalys.nl> ha
scritto::
just use a * just before an array to make it a list of parameters.>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)
Btw, maybe you could just use
print Date.strftime(yourformat)
gabriele renzi Guest
-
Fred Werne #4
Re: array -> list
Hi Wybo
Wybo Dekker schrieb:Do you mean *anArray ?>
> Is there a way to convert an array to a (parameter-)list?
I tested the following> 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)
---------------------------------------------------
dateArray = [1973,11,9,11,30]
printf("%04d-%02d-%02d %02d:%02d\n", *dateArray)
---------------------------------------------------
It works.
I don't have a class ParseDate with a method parse,
but if it returns an Array, I think
printf("%04d-%02d-%02d %02d:%02d\n", *ParseDate.parse(datestring))
^ ^
will work.
I hope, I understand your problem.
Regards
Fred from Wuppertal, Germany
Fred Werne Guest
-
Wybo Dekker #5
Re: array -> list
On Sat, 15 Nov 2003, ts wrote:
Great! That's just what I was looking for;> ruby -rparsedate \
> -e 'printf("%04d-%02d-%02d %02d:%02d\n",
> *ParseDate.parsedate(Time.now.to_s))'
> 2003-11-15 13:31
I now could even find it in the book; thanks!
--
Wybo
Wybo Dekker Guest



Reply With Quote

