# Help array di array

**URL:** <https://www.ruby-forum.com/t/help-array-di-array/180634>\
**Category:** IT\
**Created:** [December 24, 2009, 11:47am UTC](https://www.ruby-forum.com/t/help-array-di-array/180634 "2009-12-24T11:47:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![al\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@al\_S](https://www.ruby-forum.com/u/al_S)\
**Post date:** [December 24, 2009, 11:47am UTC](https://www.ruby-forum.com/t/help-array-di-array/180634/1 "2009-12-24T11:47:06Z")

</div>

Ciao a tutti,

sto combattendo con una funziona simile a questa:

function([“x”,“y”,“x”]) do |a,b|c|  
printf("%10s %10s %10s\n",a,b,c)  
end

Funziona bene ma il mio obbiettivo Ã¨ scrivere una cosa del genere :

new array

function([“x”,“y”,“z”]) do |a,b|c|  
push a,b,c into array  
end

if array is not empty  
printf("%10s %10s %10s\n",a,b,c)  
end

Qual’e’ il modo migliore per realizzarlo?

Grazie mille,  
Al

---

<div class="post-metadata">

**Author:** ![al\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@al\_S](https://www.ruby-forum.com/u/al_S)\
**Post date:** [December 24, 2009, 1:10pm UTC](https://www.ruby-forum.com/t/help-array-di-array/180634/2 "2009-12-24T13:10:05Z")

</div>

Alfonso C. wrote:

> new array
> 
> function([“x”,“y”,“z”]) do |a,b|c|  
> push a,b,c into array  
> end
> 
> if array is not empty  
> printf("%10s %10s %10s\n",a,b,c)  
> end
> 
> Qual’e’ il modo migliore per realizzarlo?

usare direttamente push invece che una funzione che fa solo push ?

---

<div class="post-metadata">

**Author:** ![al\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@al\_S](https://www.ruby-forum.com/u/al_S)\
**Post date:** [December 24, 2009, 3:08pm UTC](https://www.ruby-forum.com/t/help-array-di-array/180634/3 "2009-12-24T15:08:52Z")

</div>

Alessandro S. wrote:

> Alfonso C. wrote:
> 
> > new array
> > 
> > function([“x”,“y”,“z”]) do |a,b|c|  
> > push a,b,c into array  
> > end
> > 
> > if array is not empty  
> > printf("%10s %10s %10s\n",a,b,c)  
> > end
> > 
> > Qual’e’ il modo migliore per realizzarlo?
> 
> usare direttamente push invece che una funzione che fa solo push ?

mmhh in realtÃ la funziona mi ritorna i valori di a,b,c

sto provando un po’ di cose della serie :

array = []

funziona([“x”,“y”]) do |a,b|  
array.push(["#{a.value}"],["#{b.value}"])  
end

array.each {|x,y| printf("%20s %s\n",x,y)}

che ne pensate?

---

<div class="post-metadata">

**Author:** ![al\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@al\_S](https://www.ruby-forum.com/u/al_S)\
**Post date:** [December 24, 2009, 3:17pm UTC](https://www.ruby-forum.com/t/help-array-di-array/180634/4 "2009-12-24T15:17:20Z")

</div>

Alfonso C. wrote:

> Alessandro S. wrote:
> 
> > Alfonso C. wrote:
> > 
> > > new array
> > > 
> > > function([“x”,“y”,“z”]) do |a,b|c|  
> > > push a,b,c into array  
> > > end
> > > 
> > > if array is not empty  
> > > printf("%10s %10s %10s\n",a,b,c)  
> > > end
> > > 
> > > Qual’e’ il modo migliore per realizzarlo?
> > 
> > usare direttamente push invece che una funzione che fa solo push ?
> 
> mmhh in realtÃ la funziona mi ritorna i valori di a,b,c
> 
> sto provando un po’ di cose della serie :
> 
> array = []
> 
> funziona([“x”,“y”]) do |a,b|  
> array.push(["#{a.value}"],["#{b.value}"])  
> end
> 
> array.each {|x,y| printf("%20s %s\n",x,y)}
> 
> che ne pensate?

ops c’e’ da fare una correzione:

array.push([["#{a.value}"],["#{b.value}"]])

cosÃ¬ sembra funzionare! 🙂

---

<div class="post-metadata">

**Author:** ![al\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@al\_S](https://www.ruby-forum.com/u/al_S)\
**Post date:** [December 25, 2009, 3:16pm UTC](https://www.ruby-forum.com/t/help-array-di-array/180634/5 "2009-12-25T15:16:50Z")

</div>

se ho capito bene, ti occorre un metodo che prendendo un array di  
elementi in input, restituisca un array contentente un ulteriore array  
per elemento, giusto? questo funziona senza sforzi 😉

def prova(\*args)  
args.collect {|x| [x]}  
end

ciao,  
A.

Alfonso C. ha scritto:
