# Strangeness with string concatenation and function return va

**URL:** <https://www.ruby-forum.com/t/strangeness-with-string-concatenation-and-function-return-va/103130>\
**Category:** Ruby\
**Created:** [May 2, 2007, 4:28am UTC](https://www.ruby-forum.com/t/strangeness-with-string-concatenation-and-function-return-va/103130 "2007-05-02T04:28:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [May 2, 2007, 4:28am UTC](https://www.ruby-forum.com/t/strangeness-with-string-concatenation-and-function-return-va/103130/1 "2007-05-02T04:28:24Z")

</div>

I get an error when running code snippet A, but if I change it to B,  
there’s  
no error. I’m not familiar enough with Ruby to know why this is. Could  
someone explain this?

----- A -----  
def ReturnString ( )  
return “abc”  
end

File.open ( “junk.txt” , “w” ) do | f |  
f.write ( ReturnString ( ) + “\n” )  
end

----- B -----  
def ReturnString ( )  
return “abc”  
end

File.open ( “junk.txt” , “w” ) do | f |  
s = ReturnString ( )  
f.write ( s + “\n” )  
end

If it makes any difference, I’m running Ruby under Windows.

Mike S.

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [May 2, 2007, 5:26am UTC](https://www.ruby-forum.com/t/strangeness-with-string-concatenation-and-function-return-va/103130/2 "2007-05-02T05:26:28Z")

</div>

On 5/2/07, Jesse M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ‘abc’  
> [http://www.jessemerriman.com/](http://www.jessemerriman.com/)

Jesse explained the problem.  
I ran your code and there were no errors in one version but there were  
warnings about the spaces before parentheses. It is a good idea to  
heed warnings and try to make them go away.

Harry

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [May 2, 2007, 5:05am UTC](https://www.ruby-forum.com/t/strangeness-with-string-concatenation-and-function-return-va/103130/3 "2007-05-02T05:05:25Z")

</div>

On Tuesday 01 May 2007 22:27, Mike S. wrote:

> ```
> f.write ( ReturnString ( ) + "\n" )
> 
> ```
> 
> end

You can’t have that space between ReturnString and the parenthesis (you  
sure  
like lots of spaces, eh?). Here’s one way of doing it that should work:

def return\_string  
‘abc’  
end

File.open(‘junk.txt’, ‘w’) do |f|  
f.puts return\_string  
end
