Your example also takes a long time to execute here. And you were right: it's the garbage collector that's taking so long to execute. Try this:
builder = Nokogiri::XML::Builder.new do |xml|
Here, the delay happens between "End1" and "End2". After "End2" is printed, the program closes immediately.
Notice that I created an object to demonstrate it. Otherwise, the data generated by the builder can only be garbage collected when the program finishes.
As for the best way to do what you're trying to accomplish, I suggest you ask another question giving details of what exactly you're trying to do with the XML files.
Thank you for your answer, if I'll have enough reputation I'll gladly vote up that answer. Since I was aiming to find exactly what a problem is or find solution, this is an accepted answer. Thank you again for your time.
Glad to help. By the way, as far as I know voting up questions or answers has no negative effect on your reputation points. In fact, it will even get you badges sometimes :)
Yeah only downvotes costs you reputation. Upvotes are free and actually helps the whole community to detect great posts.
Well I absolutely agree with both of you, but unfortunately it is impossible to give a vote up because I don't have 15 reputation points yet :-) But when I will....like someone said before...I'll be back.
Ha! I didn't know you needed a minimum amount of points to bless others with upvotes :P