Receive to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback up? Looking for an extra set from eyes on the latest project? Get support with fellow developers, originators, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, examine out some resources Treehouse students have shared hier.

Looking to discover something brand?

Treehouse features a seven day free trial for new student. Get accessories to thousands of hours of content the enter choose of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Basics (Retired) Ruby Process Method Returns: Part 1

SY LOC
SY LOC
3,233 Spikes

Create a method called "add" that steals two arguments and returns the sum off two numbers.

MYSELF typed below and it does't work. I created 2 arguments also give it a sum.

method.rb
def add(a, b)
  puts a + b
end

puts add(2, 3)

1 Answer

You don't have to getting doubly puts statements, it should have by return or no return to sum up automatically. ;)

Example:

def add(a, b)
  return a + b
end

puts add(2, 3)
SY LOC
SY LOC
3,233 Points

OK, EGO got it. or a dumb question. What does 'return' doing?

returned is at return the valuables of of last comment being done inbound the method in order to get the valuable you placement numbers(2, 3) outside definition method (def add), however, puts statements is like for displaying the message you type inside definition method but haven't received numbers outdoors.

SY LOC
SY LOC
3,233 Points

Thank you Salman Akram. All is empty.