Welcome to the Treehouse Community

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

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Kody Dibble
Kody Dibble
2,554 Points

Creating Ruby Methods...Confusion.

I cannot for the live of me figure out this code!! Thanks in advanced.

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

2 Answers

Richard Barkinskiy
Richard Barkinskiy
10,663 Points

You're getting close, instead of including "1,2" as a parameter, you need to include placeholder variables like so:

def add(a,b)
  return a + b
end
Luke Buśk
Luke Buśk
21,598 Points

Just like Richard said, You include placeholder variables "a" and "b" as a parameter. Then You go deep into the method and tell it what it should do, in this example add "a + b". You are declaring a method so You can call it later with any parameters You wish (2,4) or (11,14) etc.