Created
January 28, 2013 03:50
-
-
Save yangsu/4652878 to your computer and use it in GitHub Desktop.
Ruby Module
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
module ToFile | |
def filename | |
"object_#{self.object_id}.txt" | |
end | |
def to_f | |
File.open(filename, 'w') {|f| f.write(to_s)} | |
end | |
end | |
class Person | |
include ToFile | |
attr_accessor :name | |
def initialize(name) | |
@name = name | |
end | |
def to_s | |
name | |
end | |
end | |
Person.new('Kevin').to_f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment