?? 06 - writing to a file.rb
字號(hào):
open('output', 'w') { |f| f << "This file contains great truths.\n" }open('output', 'w') do |f| f.puts 'The great truths have been overwritten with an advertisement.'endopen('output') { |f| f.read }# => "The great truths have been overwritten with an advertisement.\n"#---open('output', "a") { |f| f.puts 'Buy Ruby(TM) brand soy sauce!' }open('output') { |f| puts f.read }# The great truths have been overwritten with an advertisement.# Buy Ruby(TM) brand soy sauce!#---open('output', 'w') do |f| [1,2,3].each { |i| f << i << ' and a ' }endopen('output') { |f| f.read } # => "1 and a 2 and a 3 and a "#---open('output', 'w') do |f| f << 'This is going into the Ruby buffer.' f.flush # Now it's going into the OS buffer.endIO.sync = falseopen('output', 'w') { |f| f << 'This is going straight into the OS buffer.' }#---
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -