From: Dave Thomas Date: 2008-12-20T00:50:36+09:00 Subject: [ruby-core:20704] Re: [Feature #905] Add String.new(fixnum) to preallocate large buffer On Dec 19, 2008, at 9:33 AM, Charles Oliver Nutter wrote: > I suppose then coming up with a common name that works for both > would be a good idea. I'm back to liking "buffer" in both cases. > > String.buffer(1000) produces an empty string that can grow to 1000 > bytes without needing to resize/copy. > > Array.buffer(1000) produces an empty array that can grow to 1000 > elements without needing to resize/copy. I think the reason I dislike this is that you're creating methods that are polymorphic on the types of their arguments, and yet we generally don't do that in Ruby-level code. So by creating these methods, you're giving them a different flavor from methods that would be written in straight Ruby. How about something more Ruby-like: s = String.new(initial_capacity: 1000) t = String.new(buffer, initial_capacity: 2*buffer.length) Dave