GConf is a configuration data storage mechanism. It's one of the easiest way to store configuration data. And its features are so cool and elegant. If you are thinking of adding customization functionality to your application, check it out!
See Introduction to the GConf library. It's a nice introduction for GConf.
This is an easy but complete sample.
require 'gconf2' client = GConf::Client.new #Read data p client["/apps/hoge/stage"] p client["/apps/hoge/name"] #Write data client["/apps/hoge/stage"] = 1 client["/apps/hoge/name"] = ARGV
Save this sample as "test.rb" and execute twice.
$ruby test.rb "hoge" $ruby test.rb "fuga"
At first, it returns nils because no data is stored.
Second time around, it returns 1 and "hoge".
# If you execute it once more, you get 1 and "fuga".
That's all! You do nothing anymore. You can serialize the data and read/write data anytime!
Data is managed by gconfd, which is a per-user daemon. And they are saved to $HOME/.gconf/apps/hoge/%gconf.xml asynchronously. In this case, both of "/apps/hoge/stage" and "/apps/hoge/name" are keys. And the values are String, Numeric, true/false.
GConf::Client uses the GTK signal system. Instead of using GConf's custom callback API for notification, you can simply connect to a "value_changed" signal. Try to follow sample in 2 terminal and execute them on each terminal.
require 'gconf2' client = GConf::Client.new client.add_dir("/apps/hoge") client.notify_add("/apps/hoge/name") do |client, entry| p entry.value end Gtk.main