Help with deciphering eulers problem 3 solution

def large_prime(n)
return [] if n==1
p factor = (2…n).find {|x| n % x == 0}
p [factor] + large_prime(n/factor)
end
p large_prime(56)
the factors of 56 are [2,2,2,7]

Can someone please tell me step by step whats happening in this code
using
56 as the argument?

I dont understand how the find method is able to get all the prime
factors.
If the condition is n%x == 0, then 4 should be added onto the factors
too right?

I get that find grabs the first value that meets its condition, so
shouldn’t it be [2,4,7,14 etc] instead of [2,2,2,7]? I dont understand
how this line works…

And then 4th line. What is it doing exactly? Is it just taking n and
dividing it by all the factors? so 56/2/2/2/7 until 1?

This is really bothering me…been staring at that piece of code
forever…

Jack Mr wrote in post #1159971:

This is really bothering me…been staring at that piece of code
forever…

‘find’ stop at first matching a condition,
‘select’ extract all elements that match a condition

(1…10).find {|a| a%2==0}
=> 2
(1…10).select {|a| a%2==0}
=> [2, 4, 6, 8, 10]

So ‘(2…n).find {|x| n % x == 0}’ extract first value which match, it is
2,
tree times.