From: Michal Suchanek Date: 2009-02-16T19:52:52+09:00 Subject: [ruby-core:22182] Re: [Feature #908] Should be an easy way of reading N characters from am I/O stream 2009/2/15 Tanaka Akira : > In article , > Michal Suchanek writes: > >>> For example, zip code or some fixed numbering system is >>> fixed length but multibyte encoding is not useful. >> >> Let's make it more general - what about the first N characters or first N lines? >> >> I'm sure you can understand this is useful. > > I think I don't understand the usefulness until an actual > example is shown. > >> If a method like head(N) was implemented on it would it leave the IO >> pointing to the text after the first N records, be it chars, lines, or >> anything else? > > What is represented by the N chars? I don't understand the question. N chars are N chars, they do not represent anything else. It's actually not that hard except the synchronization is not perfect. By using chars and then lines I lost "F" irb(main):001:0> f=File.open "rom.asm" => # irb(main):002:0> f.chars.take(10) => ["0", "0", "0", "0", "0", "0", "0", "0", " ", " "] irb(main):003:0> f.lines.take(3) => ["A cli\n", "00000001 FC cld\n", "00000002 66670F0115000000 o32 lgdt [dword 0x0]\n"] irb(main):004:0> f.seek(0) => 0 irb(main):005:0> f.lines.take(1) => ["00000000 FA cli\n"] Thanks Michal