Can anyone tell me why I am getting the error ?

require 'csv'

_output_file_path =
File.expand_path('output.csv',File.dirname(__FILE__))

hash = {   'A' => [ 'v', 'x', 'y' , 'z' ] ,
           'B' => [ 'm', 'n' , 'o' ] ,
           'C' => [ 'i', 'j' , 'k' , 'l', 'm', 'n' , 'o' ]
       }

headers = hash.keys
csv_row = CSV::Row.new(headers,[],true)
csv_table = CSV::Table.new(csv_row)

headers.each do |col_name|
  csv_table[col_name] = hash[col_name]
end

p csv_table.to_csv
# ~> /home/kirti/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/csv.rb:726:in
`block in []=': undefined method `header_row?' for ["A", nil]:Array
(NoMethodError)
# ~>   from
/home/kirti/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/csv.rb:504:in
`each'
# ~>   from
/home/kirti/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/csv.rb:504:in
`each'
# ~>   from
/home/kirti/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/csv.rb:725:in
`each_with_index'
# ~>   from
/home/kirti/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/csv.rb:725:in `[]='
# ~>   from -:16:in `block in <main>'
# ~>   from -:15:in `each'
# ~>   from -:15:in `<main>'

-- 
Posted via http://www.ruby-forum.com/.