summaryrefslogtreecommitdiff
path: root/ruby/to_file.rb
diff options
context:
space:
mode:
authorGuillermo Ramos2012-03-29 19:33:22 +0200
committerGuillermo Ramos2012-03-29 19:39:37 +0200
commitd5fc25cac083e63c88a830bdcf7359f8a1dac643 (patch)
treeab4cc595da944700d2ee0d8e9d63804b4a65ba26 /ruby/to_file.rb
parent3169c1929429aa79a5dd8bee7618e4ac6f84af63 (diff)
download7l-d5fc25cac083e63c88a830bdcf7359f8a1dac643.tar.gz
[Ruby] Día 2
Diffstat (limited to 'ruby/to_file.rb')
-rwxr-xr-xruby/to_file.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/ruby/to_file.rb b/ruby/to_file.rb
new file mode 100755
index 0000000..5b6967f
--- /dev/null
+++ b/ruby/to_file.rb
@@ -0,0 +1,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