Why can I do a = * ary.flatten, but not just * ary.flatten?

ary = = [[4, 8], [15, 16], [23, 42]]

In irb why can i execute

a = *ary.flatten  # => [4,8,15,16,23,42]

but not just

*ary.flatten

which gives me an error:

SyntaxError: (irb):97: syntax error, unexpected '\n', expecting '='
    from /usr/bin/irb:12:in `<main>'

I could also perform

a,b,c,d,e,f = *ary.flatten

no problem, and the return value after pressing the key

=> [4, 8, 15, 16, 23, 42]

with a, b, c, d, e, f is now a class of Fixnum.

So what does

*ary.flatten

come back in the end? It seems like it should return individual ary elements (what exactly does this object return?), Which I can assign to something: either a (which somehow automatically becomes an array), or a separate separate variable a, b, c, d, e, f each of which is now Fixnum.

Moreover,

a = *ary.flatten.class  # => [Array]
b = ary.flatten.class   # => Array

What is the difference between [Array] and Array? (maybe I should make this a separate issue, but I can only post every 90 minutes, and I want to know now!)

0
1

Splat , . , , , .

a = 4, 8, 15, 16, 23, 42

, .

4, 8, 15, 16, 23, 42

, a SyntaxError.

,

*ary.flatten

? , ary ( ?),

. , , .

a = *ary.flatten.class  # => [Array]
b = ary.flatten.class   # => Array

[Array] Array?

Array - , [Array] - , Array.

+3

All Articles