Explicitly call self.getc/self.putc.

This commit is contained in:
Jim Menard 2009-02-10 11:41:36 -05:00
parent 07d2def0ad
commit 46317fcb6e
1 changed files with 10 additions and 10 deletions

View File

@ -201,13 +201,13 @@ module XGen
def gets(separator=$/) def gets(separator=$/)
str = '' str = ''
byte = getc byte = self.getc
return nil if byte == nil # EOF return nil if byte == nil # EOF
while byte != nil while byte != nil
s = byte.chr s = byte.chr
str << s str << s
break if s == separator break if s == separator
byte = getc byte = self.getc
end end
@lineno += 1 @lineno += 1
str str
@ -215,17 +215,17 @@ module XGen
def read(len=nil, buf=nil) def read(len=nil, buf=nil)
buf ||= '' buf ||= ''
byte = getc byte = self.getc
while byte != nil && (len == nil || len > 0) while byte != nil && (len == nil || len > 0)
buf << byte.chr buf << byte.chr
len -= 1 if len len -= 1 if len
byte = getc if (len == nil || len > 0) byte = self.getc if (len == nil || len > 0)
end end
buf buf
end end
def readchar def readchar
byte = getc byte = self.getc
raise EOFError.new if byte == nil raise EOFError.new if byte == nil
byte byte
end end
@ -250,10 +250,10 @@ module XGen
alias_method :each_line, :each alias_method :each_line, :each
def each_byte def each_byte
byte = getc byte = self.getc
while byte while byte
yield byte yield byte
byte = getc byte = self.getc
end end
end end
@ -280,14 +280,14 @@ module XGen
objs = [$_] if objs == nil || objs.empty? objs = [$_] if objs == nil || objs.empty?
objs.each { |obj| objs.each { |obj|
str = obj.to_s str = obj.to_s
str.each_byte { |byte| putc(byte) } str.each_byte { |byte| self.putc(byte) }
} }
nil nil
end end
def puts(*objs) def puts(*objs)
if objs == nil || objs.empty? if objs == nil || objs.empty?
putc(10) self.putc(10)
else else
print(*objs.collect{ |obj| print(*objs.collect{ |obj|
str = obj.to_s str = obj.to_s
@ -307,7 +307,7 @@ module XGen
raise "#@filename not opened for write" unless @mode[0] == ?w raise "#@filename not opened for write" unless @mode[0] == ?w
count = 0 count = 0
string.each_byte { |byte| string.each_byte { |byte|
putc byte self.putc byte
count += 1 count += 1
} }
count count