summaryrefslogtreecommitdiff
path: root/ruby/to_file.rb
blob: 5b6967f374d53b5c8e664500c2acc1f71fbccaa7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env 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

class Person
	include ToFile
	attr_accessor :name

	def initialize(name)
		@name = name
	end
	def to_s
		name
	end
end

Person.new("matz").to_f