Forum: Ruby String usage

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F948f711c9596cc872a66e158d67cfc0?d=identicon&s=25 Maung Aung (maung)
on 2007-07-02 21:45
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
F948f711c9596cc872a66e158d67cfc0?d=identicon&s=25 Maung Aung (maung)
on 2007-07-02 21:57
never mind, I figured that out because I was using it as class variable
and I didn't instantiate the object.
Thanks.
Maung

Maung Aung 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
This topic is locked and can not be replied to.