From: Aashish Kiran Date: 2013-03-18T21:15:31+09:00 Subject: xml parsing in blocks Hi, I was writing a small program as follows, But could not get expected output. Can anyone help. --------------------------xml_document.rb----------------------------- class XmlDocument attr_accessor :format def initialize(format = nil) self.format = format end def method_missing(name, *args, &block) self.class.class_eval do define_method(name) do |*args, &block| temp = '' if args[0] args[0].each do |k, v| temp = temp + " #{k}='#{v}'" end end if block temp = "<#{name}#{temp}>" + block.call + "" else temp = "<#{name}" + temp + "/>" end temp end end send(name, *args, &block) end end -----------------------end of xml_document.rb--------------------------- o/p : expected o/p : \n \n \n \n \n \n\n @xml = XmlDocument.new(true) @xml.hello do @xml.goodbye do @xml.come_back do @xml.ok_fine(:be => "that_way") end end end.should == "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" end -- Posted via http://www.ruby-forum.com/.