fabsy wrote:
> Hey!
> I have been trying to find a goto function in ruby..
> Like this:
>
> foo: bar
> If blabla then GOTO foo
>
> Is there any command for exiting the app?
> And how do I search ex a textfile for a certain word and delete it?
>
>
> ------
>
> if value == "2"
> 		system('clear')
> 		print "[Opening file..]\n\n"
> 			r_file = File.open( "file", "a") #Wrote this so I wouldn't get an
> error like "File doesn't exist".
> 			r_file = File.open( "file", "r")
> 			print "-----\n"
> 			print r_file.read
> 			print "-----"
> 			print "\n"
> 			system ('ruby note.rb')  #is there anyway to restart or goto the
> beginning of the script?
> 		end
>
> -----
>
> Thanks!

There is a reason why there are no gotos in Ruby or the vast majority
of modern languages. They are the complete antithesis of good program
design. You should be writing something more like this:

while value == 2
  begin
    system("clear") # This is a pretty bad idea - it's not portable and
completely unneccesary.
    puts "[Opening file...]"
    puts
    File.open("file", "r") do |file|
      puts "---"
      puts file.read
      puts "---"
    end
    system("ruby note.rb") # What is this for?
  rescue Errno:ENOENT
    puts "File does not exist."
  end
end

This program properly handles file closing and uses exception handling
to pick up problems with opening the file. Exceptions and simple loops
can produce the same result as any GOTO mess while maintaining good
structure. I would avoid system() as well, but you may have your
reasons for using it.