Created
July 1, 2010 13:57
-
-
Save nazgob/459996 to your computer and use it in GitHub Desktop.
module snippet supporting "serialization"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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