Skip to content

Commit

Permalink
* lib/csv.rb (Object#CSV, Array#to_csv, String#parse_csv):
Browse files Browse the repository at this point in the history
  Examples and documentation for CSV.
  [Bug #6880] [ruby-core:47218]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
zzak committed Sep 19, 2012
1 parent 0284ad8 commit 7b79bec
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions lib/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2359,20 +2359,41 @@ def raw_encoding(default = Encoding::ASCII_8BIT)
end
end

# Another name for CSV::instance().
# Passes +args+ to CSV::instance.
#
# CSV("CSV,data").read
# #=> [["CSV", "data"]]
#
# If a block is given, the instance is passed the block and the return value
# becomes the return value of the block.
#
# CSV("CSV,data") { |c|
# c.read.any? { |a| a.include?("data") }
# } #=> true
#
# CSV("CSV,data") { |c|
# c.read.any? { |a| a.include?("zombies") }
# } #=> false
#
def CSV(*args, &block)
CSV.instance(*args, &block)
end

class Array
# Equivalent to <tt>CSV::generate_line(self, options)</tt>.
class Array # :nodoc:
# Equivalent to CSV::generate_line(self, options)
#
# ["CSV", "data"].to_csv
# #=> "CSV,data\n"
def to_csv(options = Hash.new)
CSV.generate_line(self, options)
end
end

class String
# Equivalent to <tt>CSV::parse_line(self, options)</tt>.
class String # :nodoc:
# Equivalent to CSV::parse_line(self, options)
#
# "CSV,data".parse_csv
# #=> ["CSV", "data"]
def parse_csv(options = Hash.new)
CSV.parse_line(self, options)
end
Expand Down

0 comments on commit 7b79bec

Please sign in to comment.