From: Sam Duncan Date: 2013-08-06T05:48:59+09:00 Subject: Re: Creating variable inside a class On 06/08/13 08:35, Renato Co wrote: > All I want to do, is to create a new variable called data_dfp inside the > class, and be able to set/get it's value from outside > > require 'nokogiri' > class MyDocument < Nokogiri::XML::SAX::Document > attr_accessor :data_dfp > > def start_element(name, attrs = []) > puts "#{name}" > end > end > > parser = Nokogiri::XML::SAX::Parser.new(MyDocument.new) ^^ I'm not sure what this is supposed to mean. Have you tried simply: parser = MyDocument.new I'm not familiar with nokogiri, is it supposed to take something in its constructor? > parser.data_dfp = 4 > puts parser.data_dfp > > Error > nokoteste.rb:12:in `
': undefined method `data_dfp=' for > # (NoMethodError) > > > Whats the right way of doing this? > Sam