Why is this syntactically value
def x
return 1, 2
end
but this isn't
def y
1, 2
end
Why is this syntactically value
def x
return 1, 2
end
but this isn't
def y
1, 2
end
def x
return 1, 2
end
Here, 1 and 2 are "arguments" to the return statement. It can handle
many of them perfectly well.
def y
1, 2
end
This is invalid syntax - Ruby has no comma operator (unlike, say, C),
and it simply doesn't know what to do with this code. Commas are only
allowed (I hope I won't miss anything) in multiple assignment, in
method/block argument list, and in "argument lists" of some language
constructs, like return, rescue or throw.
-- Matma Rex
Thursday, February 9, 2012, 1:35:39 PM, you wrote:
def x
return 1, 2
end
Here, 1 and 2 are "arguments" to the return statement. It can handle
many of them perfectly well.
def y
1, 2
end
This is invalid syntax - Ruby has no comma operator (unlike, say, C),
and it simply doesn't know what to do with this code. Commas are only
allowed (I hope I won't miss anything) in multiple assignment, in
method/block argument list, and in "argument lists" of some language
constructs, like return, rescue or throw.
Matma,
So, wouldn't a more consistent and more understandable way of doing things be
def x
return [1, 2]
end
def y
[1, 2]
end
Do as you please.
Cheers
robert
On Fri, Feb 10, 2012 at 8:16 AM, Ralph Shnelvar <ralphs@dos32.com> wrote:
Thursday, February 9, 2012, 1:35:39 PM, you wrote:
So, wouldn't a more consistent and more understandable way of doing things bedef x
return [1, 2]
enddef y
[1, 2]
end
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/