Why is this syntactically valid
def x
return 1, 2
end
but this isn’t
def y
1, 2
end
Why is this syntactically valid
def x
return 1, 2
end
but this isn’t
def y
1, 2
end
Because ‘return’ takes an argument, and ruby infers the []s.
In the second case, 1, 2 by itself is not a valid statement, it
doesn’t guess the []s.
Just do
def y
[1, 2]
end
def z
[1,2]
end
Is however valid
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs