From: Nikolai Weibull Date: 2011-01-05T04:49:53+09:00 Subject: [ruby-core:34068] Re: [ruby-core:34017] Re: [ruby-core:34012] Re: Why doesn’t StringIO implement #freeze? On Fri, Dec 31, 2010 at 12:14, Nikolai Weibull wrote: > On Fri, Dec 31, 2010 at 03:09, Nobuyoshi Nakada wrote: >> Hi, >> >> At Fri, 10 Dec 2010 00:34:35 +0900, >> Nikolai Weibull wrote in [ruby-core:33648]: >>> IO implements #freeze, but StringIO doesn���t. ��What���s up with that? >> >> What do you mean? ��IO#freeze does not exist, but just is inherited >> from Kernel, and also StringIO. > > Sorry if I was unclear. ��IO objects runs rb_check_frozen for most > methods before they actually do anything, while StringIO doesn���t. I now see that certain methods check whether the internal String is frozen and then raise an IOError. You can thus use StringIO.new("abc").string.freeze to freeze part of the StringIO. Anyway, what I really want to know now is, would it be desirable by anyone other than me that, for example, StringIO#rewind raise TypeError if the StringIO is frozen? Or is it even the case that such behavior is undesirable? The more I think about it, why is the IO code not more modularized? Why do we need a completely separate implementation of IO where the ���base��� object is a String? At least for the output part of it, it seems that implementing #write would be sufficient to include a module containing methods like #putc, #print, #puts, #printf, and similar. Most of this would be true for reading as well, if a proper interface was defined. Perhaps we don���t need something as ���advanced��� as http://library.gnome.org/devel/gio/stable/streaming.html but it seems to me that there is an opportunity for simplification here.