Permalink
Browse files

Added example to README

  • Loading branch information...
1 parent 1bfb4bb commit 6f6579a947b5d4dbd8954aa60b88566779e2c886 @delano committed May 7, 2009
Showing with 29 additions and 0 deletions.
  1. +29 −0 README.rdoc
View
@@ -2,6 +2,30 @@
Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)
+== Example
+
+ require 'storable'
+
+ class Machine < Storable
+ field :environment # Define field names for Machine. The
+ field :role # default type is String, but you can
+ field :position => Integer # specify a type using a hash syntax.
+ end
+
+ mac1 = Machine.new # Instances of Machine have accessors
+ mac1.environment = "stage" # just like regular attributes.
+ mac1.role = "app"
+ mac1.position = 1
+
+ puts "# YAML", mac1.to_yaml # Note: the field order is maintained
+ puts "# CSV", mac1.to_csv # => stage,app,1
+ puts "# JSON", mac1.to_json # Note: field order not maintained.
+
+ mac2 = Machine.from_yaml(mac1.to_yaml)
+ puts mac2.environment # => "stage"
+ puts mac2.position.class # => Fixnum
+
+
== Installation
Via Rubygems, one of:
@@ -14,6 +38,11 @@ or via download:
* storable-latest.zip[http://github.com/delano/storable/zipball/latest]
+== Prerequisites
+
+* Ruby 1.8, Ruby 1.9, or JRuby 1.2
+
+
== Credits
* Delano Mandelbaum (delano@solutious.com)

0 comments on commit 6f6579a

Please sign in to comment.