From: Neubyr Neubyr Date: 2012-06-25T13:35:58+09:00 Subject: Re: Code organization in multiple/single classes - things to consider Thanks for the reply Jan. Reply in-line below. Jan E. wrote in post #1065853: > Hi, > > I don't think there's much to be improved. Probably the send_xml method > should get the xml by calling the my_xml method rather than through the > parameter. This makes more sense and is also safer (you don't want > abritrary strings to be submitted). I was wondering about xml object validation as well and your suggestion of calling my_xml/to_xml through send_xml seems like a good approach here. > > If you're not only dealing with person data, you should write a generic > class for data processing, which generates specific classes for data > sets (like the Struct class in Ruby). > > As an example: > > Person = Data[:name, :age, :city] > person_1 = Person.new 'Frank Miller', 23, 'Manchester' > person_1.send_xml I am not sure how Person class or data structure is going to look like at the moment. But I have looked at Struct and OpenStruct classes and may use it in future revisions. > > By the way, you can and should name the method "to_xml". There's > no ambiguity with the "to_xml" of Nokogiri, because those are different > objects. You may also leave out the "require 'rubygems'" in Ruby 1.9. Yes, but I need this to be portable for Ruby 1.8.7 as well. Thanks for the suggestion on using to_xml method name in my class as well. I knew it won't be a namespace conflict, but I wasn't confident whether to use it or not.. ~ N -- Posted via http://www.ruby-forum.com/.