diff options
author | jeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-23 23:12:11 +0000 |
---|---|---|
committer | jeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-11-23 23:12:11 +0000 |
commit | 80c4b4b3d72c7841b9c2453713a5b96258f2ca90 (patch) | |
tree | e53f259797b83c2999f7d07d2b29543810731404 /lib/csv.rb | |
parent | 10ca8a4b07ea925c4a71c5da6067688fd8ff0bff (diff) | |
download | ruby-80c4b4b3d72c7841b9c2453713a5b96258f2ca90.tar.gz |
* lib/csv.rb: If skip_lines is set to a String, convert it to a Regexp
to prevent the alternative, which is that each line in the CSV gets
converted to a Regexp when calling skip_lines#match.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43823 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/csv.rb')
-rw-r--r-- | lib/csv.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/csv.rb b/lib/csv.rb index 804b941433..d66b84922a 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -1470,11 +1470,12 @@ class CSV # <b><tt>:skip_lines</tt></b>:: When set to an object responding to # <tt>match</tt>, every line matching # it is considered a comment and ignored - # during parsing. When set to +nil+ - # no line is considered a comment. - # If the passed object does not respond - # to <tt>match</tt>, <tt>ArgumentError</tt> - # is thrown. + # during parsing. When set to a String, + # it is first converted to a Regexp. + # When set to +nil+ no line is considered + # a comment. If the passed object does + # not respond to <tt>match</tt>, + # <tt>ArgumentError</tt> is thrown. # # See CSV::DEFAULT_OPTIONS for the default settings. # @@ -2120,10 +2121,12 @@ class CSV # Stores the pattern of comments to skip from the provided options. # # The pattern must respond to +.match+, else ArgumentError is raised. + # Strings are converted to a Regexp. # # See also CSV.new def init_comments(options) @skip_lines = options.delete(:skip_lines) + @skip_lines = Regexp.new(@skip_lines) if @skip_lines.is_a? String if @skip_lines and not @skip_lines.respond_to?(:match) raise ArgumentError, ":skip_lines has to respond to matches" end |