StringIO

StringIO based on code by MoonWolf

Public Class Methods

new(string="") click to toggle source
 
               # File syck/lib/syck/stringio.rb, line 11
def initialize(string="")
    @string=string
    @pos=0
    @eof=(string.size==0)
end
            

Public Instance Methods

eof() click to toggle source
 
               # File syck/lib/syck/stringio.rb, line 19
def eof
    @eof
end
            
Also aliased as: eof?
eof?() click to toggle source
Alias for: eof
pos() click to toggle source
 
               # File syck/lib/syck/stringio.rb, line 16
def pos
    @pos
end
            
readline(rs=$/) click to toggle source
 
               # File syck/lib/syck/stringio.rb, line 23
def readline(rs=$/)
    if @eof
        raise EOFError
    else
        if p = @string[@pos..-1]=~rs
            line = @string[@pos,p+1]
        else
            line = @string[@pos..-1]
        end
        @pos+=line.size
        @eof =true if @pos==@string.size
        $_ = line
    end
end
            
rewind() click to toggle source
 
               # File syck/lib/syck/stringio.rb, line 37
def rewind
    seek(0,0)
end
            
seek(offset,whence) click to toggle source
 
               # File syck/lib/syck/stringio.rb, line 40
def seek(offset,whence)
    case whence
    when 0
        @pos=offset
    when 1
        @pos+=offset
    when 2
        @pos=@string.size+offset
    end
    @eof=(@pos>=@string.size)
    0
end
            

Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.

If you are posting code samples in your comments, please wrap them in "<pre><code class="ruby" > ... </code></pre>" markup in order to get syntax highlighting.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file a bug report so that it can be corrected for the next release. Thank you.

blog comments powered by Disqus