diff options
author | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-17 01:58:34 +0000 |
---|---|---|
committer | hsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-06-17 01:58:34 +0000 |
commit | 96fb819676d401871b7cefd261ea7182684d6ff4 (patch) | |
tree | 13e1ec6d009725037a71f557c4492d49609d0e05 /lib | |
parent | e5471cbe631cf2cb7949b46d480f68affdc29790 (diff) |
* lib/csv.rb: accept to use Range object for row selection.
[Feature #11267][ruby-dev:49091]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/csv.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index fd493d8859..e1e151b802 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -284,11 +284,15 @@ class CSV # def field(header_or_index, minimum_index = 0) # locate the pair - finder = header_or_index.is_a?(Integer) ? :[] : :assoc + finder = (header_or_index.is_a?(Integer) || header_or_index.is_a?(Range)) ? :[] : :assoc pair = @row[minimum_index..-1].send(finder, header_or_index) # return the field if we have a pair - pair.nil? ? nil : pair.last + if pair.nil? + nil + else + header_or_index.is_a?(Range) ? pair.map(&:last) : pair.last + end end alias_method :[], :field @@ -690,7 +694,7 @@ class CSV # def [](index_or_header) if @mode == :row or # by index - (@mode == :col_or_row and index_or_header.is_a? Integer) + (@mode == :col_or_row and (index_or_header.is_a?(Integer) or index_or_header.is_a?(Range))) @table[index_or_header] else # by header @table.map { |row| row[index_or_header] } |