Skip to content

Instantly share code, notes, and snippets.

@nazgob
Created July 1, 2010 13:57
Show Gist options
  • Save nazgob/459996 to your computer and use it in GitHub Desktop.
Save nazgob/459996 to your computer and use it in GitHub Desktop.
module snippet supporting "serialization"
#!/usr/bin/ruby
module ToFile
def filename
"object_#{self.object_id}.txt"
end
def to_f
File.open(filename, 'w') {|f| f.write(to_s)}
end
end #module
class Person
include ToFile
attr_accessor :name
def initialize name
@name = name
end
def to_s
name
end
end
Person.new('nazgob').to_f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment