2013-04-04 27 views
-1
class Arun 
    def arun 
    afile=File.new("arun1.txt") 
     if afile 
     afile.open("arun1.txt","w") 
     afile.syswrite("hi from arunkumar.............") 
     afile.close() 
     afile.open("arun1.txt","r+") 
     con=afile.sysread(30) 

     puts con 
     afile.close() 
     else 
     puts "can't open" 
     end 

    end 
end 
a=Arun.new 
a.arun 

在這裏我無法訪問arun方法的節目呼籲#<File:arun1.txt>(NoMethodError)私有方法open私有方法'打開」呼籲#<文件:arun1.txt>(NoMethodError)

回答

1

有一個看看Ruby documentstion on File IO

具體來說,爲了寫一個文件只需要使用像

File.open("arun.txt", 'w') {|f| f.write("hi from arunkumar.............") } 

由於您的錯誤表示open方法不適用於對象。

0

在程序開始時寫下面的給定語句。由於IO是一類,代表InputOutput,包含所有方法,包括打開

要求IO

相關問題