From: "Abinoam Jr." Date: 2013-08-06T00:04:57-03:00 Subject: Re: Creating variable inside a class On Mon, Aug 5, 2013 at 5:35 PM, 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) > parser.data_dfp = 4 > puts parser.data_dfp data_fp is defined at the MyDocument and not at the parser. parser.document # Returns the "MyDocument" instance you want. So you should... parser.document.data_dfp = 4 puts parser.document.data_dfp Was this what you were trying to accomplish? > > Error > nokoteste.rb:12:in `
': undefined method `data_dfp=' for > # (NoMethodError) > > > Whats the right way of doing this? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ ruby-talk mailing list ruby-talk@ruby-lang.org http://lists.ruby-lang.org/cgi-bin/mailman/listinfo/ruby-talk