# IO#gets with limit

**URL:** <https://www.ruby-forum.com/t/io-gets-with-limit/125966>\
**Category:** Development\
**Created:** [January 14, 2008, 9:32am UTC](https://www.ruby-forum.com/t/io-gets-with-limit/125966 "2008-01-14T09:32:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheepman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@sheepman](https://www.ruby-forum.com/u/sheepman)\
**Post date:** [January 14, 2008, 9:32am UTC](https://www.ruby-forum.com/t/io-gets-with-limit/125966/1 "2008-01-14T09:32:19Z")

</div>

e$B$3$s$P$s$Oe(B sheepman e$B$G$9!#e(B

IO#gets e$B$Ke(B limit e$B$rIU$1$F8F$V$He(B valid\_encoding  
e$B$8$c$J$$e(B  
e$BJ8;zNs$,JV$C$F$-$^$9!#e(B

$ cat test.txt  
e$B$$$m$Oe(B

$ cat t.rb  
#-_- coding: euc-jp -_-  
io = open(‘test.txt’, ‘r:euc-jp’)  
p s = io.gets(3)  
p s.valid\_encoding?

$ ruby-1.9 t.rb  
“e$B$$e(B\xA4”  
false
