[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

String usage

Maung Augn

7/2/2007 7:46:00 PM

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

--
Posted via http://www.ruby-....

2 Answers

Maung Augn

7/2/2007 7:58:00 PM

0

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


--
Posted via http://www.ruby-....

sohksyber

7/3/2007 4:41:00 PM

0

On Jul 2, 7:57 pm, Maung Aung <m...@atc-onlane.com> wrote:
> 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
>
> --
> Posted viahttp://www.ruby-fo... Hide quoted text -
>
> - Show quoted text -

5. Write a ruby program that accepts integer X from the keyboard and
use it to create an inverted triangle with X levels

Example:

Input: 5 Output: *****
****
***
**
*

7. Horizontal Histogram:

Write a program that accepts a set of digits (0 to 9) as input and
prints a horizontal histogram representing the occurrences of each
digit.

Example:

Input: Enter a Number : 12 Output: 0
Enter 12 digits: 1 **
1,7,2,9,6,7,1,3,7,5,7,9 2 *
3 *
4
5 *
6 *
7 ****
8
9 **

7. Round off:

As a new ruby programmer write a program to accept numbers from the
keyboard round off to the nearest integer number.

Example:
Input: Enter a number 123.32 Output: 123
Input: Enter a number 324.7 Output: 325

8. Write a Ruby program that has the following menu options:
1. Area of a Triangle

2. Area of a Rectangle

3. Area of a circle

4. Exit

The user selects the number corresponding to an option. Upon selecting
a menu option, the program takes the appropriate input values from the
user and computes the result. The program is terminated if menu option
4 is selected.

Useful formulas:
Area of a Triangle = 1/2*base height
Area of a Rectangle = Length Width
Area of a Circle = r2