Skip to content

Instantly share code, notes, and snippets.

@kitop

kitop/gslyaml.rb

Forked from EmmanuelOga/gslyaml.rb
Created Jun 24, 2011
Embed
What would you like to do?
GSL::Vector to YAML
# http://tech.natemurray.com/2007/03/custom-yaml-emitter.html
require 'psych'
require 'yaml'
require 'gsl'
v = GSL::Vector.alloc 1..10
class GSL::Vector
def to_yaml_type
"!ruby.com,2011/gsl-vector"
end
def to_yaml( opts = {} )
YAML.quick_emit( self.object_id, opts ) do |out|
out.map( to_yaml_type ) do |map|
map.add("values", self.to_a)
end
end
end
end
YAML::add_domain_type( "ruby.com,2011", "gsl-vector") do |type, val|
GSL::Vector.alloc val["values"]
end
puts v == YAML.load(YAML.dump(v))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment