# Omitting "return" from last line of a method def

**URL:** <https://www.ruby-forum.com/t/omitting-return-from-last-line-of-a-method-def/260743>\
**Category:** Uncategorized\
**Created:** [January 3, 2021, 3:29am UTC](https://www.ruby-forum.com/t/omitting-return-from-last-line-of-a-method-def/260743 "2021-01-03T03:29:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stuey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a4c791/32.png) [@stuey](https://www.ruby-forum.com/u/stuey)\
**Post date:** [January 3, 2021, 3:29am UTC](https://www.ruby-forum.com/t/omitting-return-from-last-line-of-a-method-def/260743/1 "2021-01-03T03:29:15Z")

</div>

I find myself in position of an old copy of SAMS TY Ruby in 21 Days; written in regard to Ruby version 1.7

I have version 2.7.2p137 installed and I am getting by OK (in the first few chapters anyway). The book claims that a method that doesn’t contain a line with “return” in it will go ahead and return the last expression it evaluates, so that

```auto
def sumdiff(n1, n2)
	n1+n2, n1-n2
end
```

will return (keep up with me) 18, 2 if given the arguments 10, 8.

But when I tried running that I got  
syntax error, unexpected ‘,’, expecting `end’  
n1+n2, n1-n2

And then it worked fine once I reran it with “return” where it should be.

Was this functional "return"lessness a feature in Ruby 1.7 that was later removed? Or am I still doing something wrong?

---

<div class="post-metadata">

**Author:** ![SouravGoswami](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/souravgoswami/32/2543_2.png) [@SouravGoswami](https://www.ruby-forum.com/u/SouravGoswami)\
**Post date:** [January 3, 2021, 6:39am UTC](https://www.ruby-forum.com/t/omitting-return-from-last-line-of-a-method-def/260743/2 "2021-01-03T06:39:41Z")

</div>

When you use return, you pass 2 arguments and you get an array. But if you omit return, you end up with something that makes no sense to Ruby.

If you type 1, 2 in bare Ruby, you get syntax error, because 1, 2 means nothing. You instead meant [1, 2].

Similarly, you need to return this:

```auto
[n1+n2, n1-n2]

```

In case of return, it accepts `*args` (multiple arguments), and returns the `*args` as an array for you. You can omit return, but you need to surround values in arrays if you are planning to return multiple values.

---

<div class="post-metadata">

**Author:** ![stuey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a4c791/32.png) [@stuey](https://www.ruby-forum.com/u/stuey)\
**Post date:** [January 3, 2021, 10:29am UTC](https://www.ruby-forum.com/t/omitting-return-from-last-line-of-a-method-def/260743/3 "2021-01-03T10:29:37Z")

</div>

Thank you Sourav!! Indeed the SAMS book got it wrong : /
