From: "Abinoam Jr." Date: 2012-01-14T04:50:33+09:00 Subject: Re: undefined method `[]=' for nil:NilClass On Fri, Jan 13, 2012 at 2:17 PM, thomas carlier wrote: > Hi, > > I am a beginner with ruby, i tried to use lightcsv but i have a problem > when i use a .csv file > > ERROR > ------------------------------------------- > /file2.rb:114:in `title=': undefined method `[]=' for nil:NilClass > (NoMethodError) >  from file1.rb:19:in `publish_post' >  from file1.rb:51 >  from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:142:in > `each' >  from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:51:in > `foreach' >  from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:82:in > `call' >  from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:82:in > `open' >  from /Library/Ruby/Gems/1.8/gems/lightcsv-0.2.2/lib/lightcsv.rb:50:in > `foreach' >  from file1.rb:48 > ------------------------------------------- > > > files concerned: > > file1.rb > ------------------------------------------- > LightCsv.foreach(config) do|row| >            begin >                post = MyClass.new(row[0], row[1], row[2]) >                [...] >            end >        end > ------------------------------------------- > > > file2.rb > ------------------------------------------- > if real.is_a? String > [...] > else >      define_method("#{key}=") do |value| >            @form[real] = value >       end > end > ------------------------------------------- > > if i replace row in file1.rb by row = [data1, data2, data3] it works > > If someone can help me :D > > -- > Posted via http://www.ruby-forum.com/. Thomas, The backtrace shows the line number where the exception was raised. If you send the whole code attached would be easier to help you debug it. By the fragments you sent the only thing I can infer is... you are trying to use the []= on a nil object. Abinoam Jr.