跳至主要内容

博文

目前显示的是标签为“ruby”的博文

Seven Languages in Seven Weeks

This morning, after 10 minutes struggle of do or do not follow the self study section. Just spend several hours of searching, coding and debugging, finally I got the following ruby script that is able to pass the self study excise. diff -r 9efeca9bd507 learning/ruby/acts_as_csv_module.rb --- a/learning/ruby/acts_as_csv_module.rb Tue Feb 07 15:13:11 2017 +0800 +++ b/learning/ruby/acts_as_csv_module.rb Tue Feb 07 15:13:49 2017 +0800 @@ -1,32 +1,90 @@ module ActsAsCsv + def self.included(base) base.extend ClassMethods end + module ClassMethods + def acts_as_csv include InstanceMethods end + + def acts_as_enumerable + include Enumerable + end end + module InstanceMethods + def read @csv_contents = [] filename = self.class.to_s.downcase + '.txt' file = File.new(filename) - @headers = file.gets.chomp.split(', ' ) + CsvRow.headers = file.gets.chomp.spl...