• 1.
    filename = ARGV.first  #è?·å??æ??æ¡£å??称
  • 2.
    script = $0   #???
  • 3.
     
  • 4.
    #���符串
  • 5.
    puts "We're going to erase #{filename}."   
  • 6.
    puts "If you don't want that, hit CTRL-C (^C)."
  • 7.
    puts "If you do want that, hit RETURN."
  • 8.
     
  • 9.
    print "?"
  • 10.
     
  • 11.
    STDIN.gets  #è¾?å?¥ 没æ??èµ?äº?å?¼ å?³å??车 就好
  • 12.
     
  • 13.
    puts "Opening the file..."  #���符串
  • 14.
    target = File.open(filename, 'w')  #ç»?targetèµ?äº?å?¼ æ??å¼?第ä¸?è¡?filenameç??æ??件 w代表å°?å?¨ æ??档中å??å?¥å??容
  • 15.
     
  • 16.
    puts "Now I'm going to ask you for three lines." #�符串
  • 17.
     
  • 18.
    print "line 1: "; line1 = STDIN.gets.chomp()#æ??档第ä¸?è¡?ç??è¾?å?¥ä¸?è¾?å?ºã??
  • 19.
    print "line 2: "; line2 = STDIN.gets.chomp()#æ??档第äº?è¡?ç??è¾?å?¥ä¸?è¾?å?º
  • 20.
    print "line 3: "; line3 = STDIN.gets.chomp()#æ??档第äº?è¡?ç??è¾?å?¥ä¸?è¾?å?º
  • 21.
     
  • 22.
    puts "I'm going to write these to the file." #�符串
  • 23.
     
  • 24.
    target.write(line1)  #writeæ?¯å??å?¥ targetç?®æ ? å°±æ?¯å??å?¥ç?®æ ?line1
  • 25.
    target.write("\n")
  • 26.
    target.write(line2)
  • 27.
    target.write("\n")
  • 28.
    target.write(line3)
  • 29.
    target.write("\n")
  • 30.
     
  • 31.
    puts "And finally, we close it." #�符串
  • 32.
    target.close() #ç?®æ ?æ??件å?³é?­
filename = ARGV.first #è?·å??æ??æ¡£å??称 script = $0 #??? #è¾?å?ºå­?符串 puts "We're going to erase #{filename}." puts "If you don't want that, hit CTRL-C (^C)." puts "If you do want that, hit RETURN." print "?" STDIN.gets #è¾?å?¥ 没æ??èµ?äº?å?¼ å?³å??车 就好 puts "Opening the file..." #è¾?å?ºå­?符串 target = File.open(filename, 'w') #ç»?targetèµ?äº?å?¼ æ??å¼?第ä¸?è¡?filenameç??æ??件 w代表å°?å?¨ æ??档中å??å?¥å??容 puts "Now I'm going to ask you for three lines." #å­?符串 print "line 1: "; line1 = STDIN.gets.chomp()#æ??档第ä¸?è¡?ç??è¾?å?¥ä¸?è¾?å?ºã?? print "line 2: "; line2 = STDIN.gets.chomp()#æ??档第äº?è¡?ç??è¾?å?¥ä¸?è¾?å?º print "line 3: "; line3 = STDIN.gets.chomp()#æ??档第äº?è¡?ç??è¾?å?¥ä¸?è¾?å?º puts "I'm going to write these to the file." #å­?符串 target.write(line1) #writeæ?¯å??å?¥ targetç?®æ ? å°±æ?¯å??å?¥ç?®æ ?line1 target.write("\n") target.write(line2) target.write("\n") target.write(line3) target.write("\n") puts "And finally, we close it." #å­?符串 target.close() #ç?®æ ?æ??件å?³é?­

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter