diff options
author | Guillermo Ramos | 2012-03-29 19:33:22 +0200 |
---|---|---|
committer | Guillermo Ramos | 2012-03-29 19:39:37 +0200 |
commit | d5fc25cac083e63c88a830bdcf7359f8a1dac643 (patch) | |
tree | ab4cc595da944700d2ee0d8e9d63804b4a65ba26 /ruby/to_file.rb | |
parent | 3169c1929429aa79a5dd8bee7618e4ac6f84af63 (diff) | |
download | 7l-d5fc25cac083e63c88a830bdcf7359f8a1dac643.tar.gz |
[Ruby] Día 2
Diffstat (limited to 'ruby/to_file.rb')
-rwxr-xr-x | ruby/to_file.rb | 24 |
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 |