# Question about return and access control

**URL:** <https://www.ruby-forum.com/t/question-about-return-and-access-control/54996>\
**Category:** Ruby\
**Created:** [March 16, 2006, 12:00am UTC](https://www.ruby-forum.com/t/question-about-return-and-access-control/54996 "2006-03-16T00:00:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@felipe](https://www.ruby-forum.com/u/felipe)\
**Post date:** [March 16, 2006, 12:00am UTC](https://www.ruby-forum.com/t/question-about-return-and-access-control/54996/1 "2006-03-16T00:00:56Z")

</div>

I’m reading PickAxe book and just finished reading chapter 3, which  
talks about classes, objects and variables. While this chapter (and the  
whole book so far) was very informative, I have two doubts:

- return seems to be used when defining methods and nowhere else. Why  
use it (why not use puts)?
- Why and where specify access control (public, protected and private  
methods)? The examples in the book weren’t clear enough.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![felipe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/90db22/32.png) [@felipe](https://www.ruby-forum.com/u/felipe)\
**Post date:** [March 16, 2006, 6:20am UTC](https://www.ruby-forum.com/t/question-about-return-and-access-control/54996/2 "2006-03-16T06:20:56Z")

</div>

Felipe wrote:

> I’m reading PickAxe book and just finished reading chapter 3, which  
> talks about classes, objects and variables. While this chapter (and the  
> whole book so far) was very informative, I have two doubts:
> 
> - return seems to be used when defining methods and nowhere else. Why  
> use it (why not use puts)?

return and puts are distinctly different.  
“puts” always sends the value to STDOUT, and the control passes to the  
next statement.  
“return” makes the available to its receiver (at the caller of  
the method in where the “return” statement exists), and control  
transfers to the next statement after that receiver.

> - Why and where specify access control (public, protected and private  
> methods)? The examples in the book weren’t clear enough.

Chapter 3 is just an introduction to access control. You then know  
that there ARE these differences. Why these differences exists, and  
how to know what methods of a class or module can be accessed, and  
under what circumstances, becomes clearer in later chapters.  
When studying class inheritance, you will see that the types of  
control affect which of the methods declared are available to an  
instance of  
a class that has inheritance. Examples there will make the  
distinctions  
clear. (and the error messages from the interpreter provide any help  
needed.) Access control is important concept because it improves the  
reliability of the program, and can limit possible bugs.
