Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My first Ruby script, got a lot of problem. Help?

Status
Not open for further replies.

arghx1

MIS
Mar 8, 2009
1
0
0
Hello,

I'm a total noob, newbie, or whatever you called a stranger to Ruby!

Just read into Ruby like 4 days ago.

For practicing, I started to write my first script. It's nothing special, just a simple script. I found out that there is a lot of problem with it. It may be syntax problems, or logic problems! Can you read the script that I coded, and help point me in the right direction?

First, my script is at
Second, a first problem I have encountered is that the method ask_file is acting weird. When run the script, I'm stuck at this part where the ask_file method asked for user input, but it does not end, and it does not break out of user input so the next instruction can process.

Please help me point out other problems if you find in my script.

Thanks in advance...
 
Hi

arghx1 said:
the method ask_file is acting weird.
There is nothing weird there. [tt]gets[/tt] reads from STDIN until the specified input separator is encountered :
Code:
[blue]irb(main):001:0>[/blue] gets("/\w/")
/my/fair/path/w/
=> "\n/my/fair/path/w/"
And that [tt]to_s[/tt] is pointless there as [tt]gets[/tt] already returns [tt]String[/tt].

By the way, [tt]waiting =~ "Y"[/tt] may not do what you are expecting if the second argument of [tt]=~[/tt] is not a [tt]Regexp[/tt].

Better remove those [tt]"#{@dirname}"[/tt] variable interpolations because are pointless. Just put the variable name there. But this is only ugliness ( which also slows down the execution ).
Code:
File.exist?(@dirname)

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top