Skip to content

Instantly share code, notes, and snippets.

@yangsu
Created January 28, 2013 03:50
Show Gist options
  • Save yangsu/4652878 to your computer and use it in GitHub Desktop.
Save yangsu/4652878 to your computer and use it in GitHub Desktop.
Ruby Module
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