?? 11 - reading and writing configuration files.rb
字號(hào):
require 'yaml'configuration = { 'color' => 'blue', 'font' => 'Septimus', 'font-size' => 7 }open('text.cfg', 'w') { |f| YAML.dump(configuration, f) }open('text.cfg') { |f| puts f.read }# --- # font-size: 7# color: blue# font: Septimusopen('text.cfg') { |f| YAML.load(f) }# => {"font-size"=>7, "color"=>"blue", "font"=>"Septimus"}#---configuration = [ { 'name' => 'Alice', 'donation' => 50 }, { 'name' => 'Bob', 'donation' => 15, 'currency' => "EUR" } ]open('donors.cfg', 'w') { |f| YAML.dump(configuration, f) }open('donors.cfg') { |f| puts f.read }# ---# - name: Alice# donation: 50# - name: Bob# donation: 15# currency: EUR#---puts ({ 'measurements' => 'metric' }.to_yaml)# --- # measurements: metricputs ({ :measurements => :metric }.to_yaml)# --- # :measurements: :metric#---
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -