How ruby ​​analysis 2/3/4 as 2 ÷ 3 ÷ 4?

A lot of ruby ​​syntax and parsing is relatively logical, but am I confused by how Ruby knows from the context, what 2 /3/ 4is 2 ÷ 3 ÷ 4 instead of parsing /3/as a regular expression? This is the correct parsing, but is /3/also a valid regular expression and how it finds out that /3/it is not a regular expression.

I thought it might be a numerical literal thing, but if you do

a = 6
b = 4
c = 2

a /b/ c

Ruby still parses this as a division. How it works?

Actually, I realized that this question is more

let's say i have it

def a(x)
  x
end

a = 4
b = 2
i = 4

a /b/i #=> 0

How is it a /b/ianalyzed as 0instead of /b/i as in why is it a /b/ianalyzed as a./(b./(i))instead of a(/b/i)?

+4
1

Ruby ( ) . , Ruby :

(a./(b))./(c)

, , Ruby , , .

.

+5

Source: https://habr.com/ru/post/1665796/


All Articles