2010-09-10 4 views
151

루비의 File.open은 모드와 옵션을 인수로 사용합니다. 모드 및 옵션의 전체 목록은 어디에서 찾을 수 있습니까?Ruby File.open 모드 및 옵션은 무엇입니까?

+0

http://ruby-doc.org/core-2.0.0/IO.html#method-c-new-label-IO+Open+Mode -이 링크는 페이지는 Daniels의 답변에 있지만 페이지를 스크롤하려면 스크롤해야합니다. 다음은 문서의 관련 부분에 대한 직접 링크입니다. – newUserNameHere

답변

311

Ruby IO module documentation에 있습니다.

Mode | Meaning 
-----+-------------------------------------------------------- 
"r" | Read-only, starts at beginning of file (default mode). 
-----+-------------------------------------------------------- 
"r+" | Read-write, starts at beginning of file. 
-----+-------------------------------------------------------- 
"w" | Write-only, truncates existing file 
    | to zero length or creates a new file for writing. 
-----+-------------------------------------------------------- 
"w+" | Read-write, truncates existing file to zero length 
    | or creates a new file for reading and writing. 
-----+-------------------------------------------------------- 
"a" | Write-only, starts at end of file if file exists, 
    | otherwise creates a new file for writing. 
-----+-------------------------------------------------------- 
"a+" | Read-write, starts at end of file if file exists, 
    | otherwise creates a new file for reading and 
    | writing. 
-----+-------------------------------------------------------- 
"b" | Binary file mode (may appear with 
    | any of the key letters listed above). 
    | Suppresses EOL <-> CRLF conversion on Windows. And 
    | sets external encoding to ASCII-8BIT unless explicitly 
    | specified. 
-----+-------------------------------------------------------- 
"t" | Text file mode (may appear with 
    | any of the key letters listed above except "b"). 
+1

모에 목록을 보내 주셔서 감사합니다. 그러나 옵션 목록은 어디에 있습니까 : File.open (filename, mode = "r"[, opt]) => 파일 –

+1

어디서 찾았습니까? 불행하게도, 문서에서'File.open (filename, mode = "r"[, opt])'을 찾을 수 없습니다. –

+0

@floatless. File 클래스의 API에서. "File"클래스로 가서 "open"메소드를 클릭하십시오. –

6

opt은 루비 1.9의 새로운 기능입니다. 다양한 옵션은 IO.new에 문서화되어 있습니다. www.ruby-doc.org/core/IO.html

+0

불행히도, 그 링크는 이제 낡은 것처럼 보입니다! –

+1

최근 루비에 대한 IO 문서를 가리 키도록 링크가 업데이트되었습니다. – Shadwell

관련 문제