mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	csv.rb: foreach enumerator
* lib/csv.rb (CSV.foreach): support enumerator. based on a patch by Hanmac (Hans Mackowiak) at [ruby-core:57643]. [ruby-core:57283] [Feature #8929] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									6c4387b4f2
								
							
						
					
					
						commit
						28204c67ed
					
				
					 3 changed files with 13 additions and 0 deletions
				
			
		|  | @ -1,3 +1,9 @@ | ||||||
|  | Fri Oct  4 09:32:33 2013  Nobuyoshi Nakada  <nobu@ruby-lang.org> | ||||||
|  | 
 | ||||||
|  | 	* lib/csv.rb (CSV.foreach): support enumerator.  based on a patch by | ||||||
|  | 	  Hanmac (Hans Mackowiak) at [ruby-core:57643].  [ruby-core:57283] | ||||||
|  | 	  [Feature #8929] | ||||||
|  | 
 | ||||||
| Thu Oct  3 18:20:47 2013  Nobuyoshi Nakada  <nobu@ruby-lang.org> | Thu Oct  3 18:20:47 2013  Nobuyoshi Nakada  <nobu@ruby-lang.org> | ||||||
| 
 | 
 | ||||||
| 	* win32/win32.c (console_emulator_p, constat_handle): disable built-in | 	* win32/win32.c (console_emulator_p, constat_handle): disable built-in | ||||||
|  |  | ||||||
|  | @ -1116,6 +1116,7 @@ class CSV | ||||||
|   # but transcode it to UTF-8 before CSV parses it. |   # but transcode it to UTF-8 before CSV parses it. | ||||||
|   # |   # | ||||||
|   def self.foreach(path, options = Hash.new, &block) |   def self.foreach(path, options = Hash.new, &block) | ||||||
|  |     return to_enum(__method__, path, options) unless block | ||||||
|     open(path, options) do |csv| |     open(path, options) do |csv| | ||||||
|       csv.each(&block) |       csv.each(&block) | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  | @ -40,6 +40,12 @@ class TestCSV::Interface < TestCSV | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   def test_foreach_enum | ||||||
|  |     CSV.foreach(@path, col_sep: "\t", row_sep: "\r\n").zip(@expected) do |row, exp| | ||||||
|  |       assert_equal(exp, row) | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   def test_open_and_close |   def test_open_and_close | ||||||
|     csv = CSV.open(@path, "r+", col_sep: "\t", row_sep: "\r\n") |     csv = CSV.open(@path, "r+", col_sep: "\t", row_sep: "\r\n") | ||||||
|     assert_not_nil(csv) |     assert_not_nil(csv) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 nobu
						nobu