⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 11 - reading and writing configuration files.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
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#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -