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
[]

Reading a local Rails file

begin
	f = File.open("#{RAILS_ROOT}/public/#{@mediaitem.path}","r")
	textcontents = f.read
ensure
	f.close
end
return textcontents

August 31st, 2008 Posted by | ruby | no comments
[]