# String usage

**URL:** <https://www.ruby-forum.com/t/string-usage/108374>\
**Category:** Ruby\
**Created:** [July 2, 2007, 9:45pm UTC](https://www.ruby-forum.com/t/string-usage/108374 "2007-07-02T21:45:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@maung](https://www.ruby-forum.com/u/maung)\
**Post date:** [July 2, 2007, 9:45pm UTC](https://www.ruby-forum.com/t/string-usage/108374/1 "2007-07-02T21:45:27Z")

</div>

Hi all,  
I have a question about string usage. I assign @test\_string class  
variable which is assigned the name of a text file.  
@test\_string = ‘file.txt’  
When I was trying to use it as a parameter in a statement  
info=File.open(@test\_string) {|f| f.read.split},  
it said “TypeError: can’t convert nil into String”. I check the type of  
@test\_string and it said String object. What am I missing?

Then I try to use to\_s method, and it said "Errno::ENOENT: No such file  
or directory - "

Could someone explain what is going here? Pls kind on me as I am new to  
Ruby.

Thanks,  
Maung

---

<div class="post-metadata">

**Author:** ![maung](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ac91a4/32.png) [@maung](https://www.ruby-forum.com/u/maung)\
**Post date:** [July 2, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/string-usage/108374/2 "2007-07-02T21:57:42Z")

</div>

never mind, I figured that out because I was using it as class variable  
and I didn’t instantiate the object.  
Thanks.  
Maung

Maung A. wrote:

> Hi all,  
> I have a question about string usage. I assign @test\_string class  
> variable which is assigned the name of a text file.  
> @test\_string = ‘file.txt’  
> When I was trying to use it as a parameter in a statement  
> info=File.open(@test\_string) {|f| f.read.split},  
> it said “TypeError: can’t convert nil into String”. I check the type of  
> @test\_string and it said String object. What am I missing?
> 
> Then I try to use to\_s method, and it said "Errno::ENOENT: No such file  
> or directory - "
> 
> Could someone explain what is going here? Pls kind on me as I am new to  
> Ruby.
> 
> Thanks,  
> Maung
