I am new to ruby , can someone explain what the second and 3rd line do?
a = [6,7,8]
a.send :[]=,0,2
a[0] + a.[](1) + a.send(:[],2)
First line is assigning an array to the variable a.
I am totally lost on second and third line. hope someone can give some detail explannations.
Thanks!!!
.sendinvokes the method identified by symbol, passing it any arguments specified.is same as
Means invoke []= method on the array object with first parameter as
0and second parameter as2.So this is
a[0] = 2, set the first element of the array to2.After executed
a.send :[]=,0,2,abecomes[2, 7, 8].a.[](1)is same asa[1]a.send(:[], 2)is same asa.[](2)which isa[2].So
a[0] + a.[](1) + a.send(:[],2)equalsa[0] + a[1] + a[2]equals2 +7 + 8equals17.