# A problem with "puts"

**URL:** <https://www.ruby-forum.com/t/a-problem-with-puts/192870>\
**Category:** Ruby\
**Created:** [August 7, 2010, 11:22am UTC](https://www.ruby-forum.com/t/a-problem-with-puts/192870 "2010-08-07T11:22:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [August 7, 2010, 11:22am UTC](https://www.ruby-forum.com/t/a-problem-with-puts/192870/1 "2010-08-07T11:22:03Z")

</div>

Hi  
Considering that , “puts” always return “nil” why in below code the  
highlighted part of code just print the contents of  
“first,second,third,forth” variable ? for example content of “first”  
variable is “nil” and when we type “puts first” ruby must execute 2  
times “nil” .

def test1 number  
puts “test1”\*number  
end

def test2 number  
“test2”\*number  
end

def test3 number  
“test3”\*number  
puts “test3”\*number  
end

def test4 number  
puts “test4”\*number  
“test4”\*number  
end

puts “-------------------1-------------------”

first=test1(1)  
second=test2(2)  
third=test3(3)  
forth=test4(4)

puts “-------------------2-------------------”

first  
second  
third  
forth

puts “-------------------3-------------------”

* * *

puts first \*  
puts second \* \<= This is highlighted part of code  
puts third \*  
puts forth \*

* * *

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [August 7, 2010, 1:09pm UTC](https://www.ruby-forum.com/t/a-problem-with-puts/192870/2 "2010-08-07T13:09:18Z")

</div>

Hi –

On Sat, 7 Aug 2010, Amir E. wrote:

> forth=test4(4)
> 
> * * *
> 
> puts first \*  
> puts second \* \<= This is highlighted part of code  
> puts third \*  
> puts forth \*
> 
> * * *

I don’t think I understand your question. Can you show the output you  
get, and the output you expect?

David

–  
David A. Black, Senior Developer, Cyrus Innovation Inc.

The Ruby training with Black/Brown/McAnally  
Compleat Philadelphia, PA, October 1-2, 2010  
Rubyist [http://www.compleatrubyist.com](http://www.compleatrubyist.com)

---

<div class="post-metadata">

**Author:** ![amiref](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/41988e/32.png) [@amiref](https://www.ruby-forum.com/u/amiref)\
**Post date:** [August 7, 2010, 1:09pm UTC](https://www.ruby-forum.com/t/a-problem-with-puts/192870/3 "2010-08-07T13:09:53Z")

</div>

On Sat, Aug 7, 2010 at 5:22 AM, Amir E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Considering that , “puts” always return “nil” why in below code the  
> highlighted part of code just print the contents of  
> “first,second,third,forth” variable ? for example content of “first”  
> variable is “nil” and when we type “puts first” ruby must execute 2  
> times “nil” .

What output do you expect to see?
