My Snippets

To and From YAML

require 'yaml'

opts = { :first => 'Philippe', :last => 'Monnet'}

serialized = opts.to_yaml

twin_opts = YAML::load serialized

twin_opts.inspect # { :first => 'Philippe', :last => 'Monnet'}

April 4th, 2010 Posted by | ruby | no comments
[]

Converting an int to an enum value


enum Status
{
   New = 0,
   InProgress = 1,
   OnHold = 2,
   Completed = 3,
   Cancelled = 4
}

Status status1 = (Status)Enum.Parse(typeof(Status),"InProgress");
Status status2 = (Status)Enum.ToObject(typeof(Status), 1);

February 24th, 2010 Posted by | c# | no comments
[]