lundi 23 février 2015

Behavior of the '*' operator in Array in Ruby

I am a newbie in Ruby. Please explain how the * operator works in this case.



arr = [1,2,3]
p arr
arr = *[1,2,3]
p arr
*arr = [1,2,3]
p arr
arr = [1,2,3]
p *arr


OUTPUT


[1,2,3]


[1,2,3]


[1,2,3]


1


2


3


What is happening in the last case ? Is it behaving as a iterator ? Can anyone give an example as to how to use it ? Also why it has no effect in the second and third case ?


Aucun commentaire:

Enregistrer un commentaire