In article <Pine.LNX.4.21.0101010645200.26658-100000 / candle.superlink.net>,
David Alan Black  <dblack / candle.superlink.net> wrote:
>(Heavens, it's the third millenium!)
>
>> class String
>>   def rewind
>>     @current_pointer=0
>>   end
>>   def read(n)
>>     @current_pointer+=n
>>     if @current_pointer>=length
>>        @current_pointer=length
>>        nil
>
>Wouldn't it be better, if the pointer is < length, to return what's
>left of the string, even if pointer + n >= length?  Something like:
>
>     def read(n)
>       @pos += n
>       res = self[@pos - n .. @pos - 1]
>       @pos = length if @pos > length
>       res
>     end
>
>In your version, if you start reading inside the string but go past
>the end, you get nil (instead of the end of the string).  
>
>(I like @pos better than @current_pointer, because it's shorter, still
>readable, and similar to IO#pos.)

It is not  a matter of 'better'  but to follow exactly  the semantics of
IO::read . It was my understanting that if the required amount could not
be read,  the result  is nil.  If I am  wrong my  code should  change of
course. Similarly,  since as you  pointed IO uses  @pos I should  do the
same and change my variable name as you recommend.

>My main suggestion would be to think about some refactoring, such that
>the following code (or something like it) would work:
>
>   Dir["*.mp3"].each{ |f|
>     print "\n{#{f}}\n"
>     tag = ID3V2Tag.new
>     tag.get_from_stream(open(f, "rb"))

You might get unpleasantness elsewhere. For instance, my routine
.read_ID3V2tag signals by returning nil that no tag was found. How do you
propose to handle that in your version? 

>As per my previous post, I find it sort of lop-sided to put the
>knowledge of these tags in the String and IO classes.

I  think it  wonderful  that ruby  allows to  re-open  and extend  basic
classes. I  do not  find it  lop-sided. Maybe you  feel this  because it
would be impossible in other languages.

Best regards,
  Jean MICHEL