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 Methods: Are they basically just Ruby's functions?

Pretty straight forward question. I'm doing into Ruby courses and it's teaching me methods. They seem like Python and PHP's functions. Are Ruby methods essentially just functions? Or will I learn Ruby functions later and be able to distinguish them from one another?

1 Answer

In Ruby, there are not the dual concepts of "function" and "method"--Ruby only has "methods". The reason, if I understand correctly, is that everything in Ruby is an object--so all those function-like things you see are object methods.

In PHP and Python, there are both functions and methods. In both of those languages, the things called "functions" normally reside outside of classes/objects; when inside a class/object, they're called "methods", and have different rules for how they're used.

Make sense?

It clears up the function/method thing, but it leaves me in the dark due to my lack of understanding of OOP. I get the whole "everything is an object" sales pitch, but I don't understand what that means yet.

But, you've answered my question completely, so I thank you.