Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
@JRubyMethod(name = "dump_all", required = 1, optional = 1, module = true, visibility = Visibility.PRIVATE) public static IRubyObject dump_all(IRubyObject self, IRubyObject[] args) { ThreadContext context = self.getRuntime().getCurrentContext(); RubyArray objs = (RubyArray)args[0]; IRubyObject io = null; IRubyObject io2 = null; if(args.length == 2 && args[1] != null && !args[1].isNil()) { io = args[1]; } YAMLConfig cfg = YAML.config().version("1.0"); IOOutputStream iox = null; if(null == io) { io2 = self.getRuntime().fastGetClass("StringIO").callMethod(context, "new"); iox = new IOOutputStream(io2); } else { iox = new IOOutputStream(io); } Serializer ser = new JRubySerializer(new EmitterImpl(iox,cfg),new ResolverImpl(),cfg); try { ser.open(); Representer r = new JRubyRepresenter(ser, cfg); for(Iterator iter = objs.getList().iterator();iter.hasNext();) { r.represent(iter.next()); } ser.close(); } catch(IOException e) { throw self.getRuntime().newIOErrorFromException(e); } if(null == io) { io2.callMethod(context, "rewind"); return io2.callMethod(context, "read"); } else { return io; } }
This paste will be private.
From the Design Piracy series on my blog: