On 29.06.2009 22:39, Tj Holowaychuk wrote: > This is an example snippet from a library im working on > http://gist.github.com/137785 I need to be able to 'buffer' or collect > the results without yielding an object to any number of nested blocks. > > I know this can be done with method_missing etc but my brain hurts haha > and for some stupid reason im stuck with this issue and have the > incorrect output below > > Output: > <ul > > <li > > </li> > > <li > > <li > > </li> > > </li> > > <li > > <li > > </li> > > <li > > <li > > </li> > > </li> > > </li> > </ul> It seems you are trying to solve not a buffering problem but rather want some kind of context present for every tag you generate. You can do so by having the context in an object. class Context def initialize @out = "" end def tag(name, &b) if b @out << "<" << name << ">" instance_eval(&b) @out << "</" << name << ">" else @out << "<" << name << "/>" end end def text(s) @out << s end end def markup(&b) c = Context.new c.instance_eval(&b) c end mup = markup do tag "foo" do tag "bar" do text "blah" end tag "empty" end end Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/