Class: IO
- Inherits:
-
Object
- Object
- IO
- Defined in:
- lib/rgnuchess.rb
Overview
Library RGnuchess allows Ruby interaction with the gnuchess program. Copyright © 2005 Leon Barrett
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
You may contact the library's author, Leon Barrett, at
Electronic mail:
[email protected]
Physical mail:
1932 Hearst Ave. Apt. F
Berkeley, CA 94709
Instance Method Summary collapse
-
#getc_until(char, iters = 1) ⇒ Object
Read characters until we see character char iters times.
-
#gets_until(regexp = //, iters = 1) ⇒ Object
Read lines until we match regexp iters times.
Instance Method Details
#getc_until(char, iters = 1) ⇒ Object
Read characters until we see character char iters times.
27 28 29 30 31 |
# File 'lib/rgnuchess.rb', line 27 def getc_until( char, iters=1 ) chars=[] (chars << (c=getc)) until c==char return chars end |
#gets_until(regexp = //, iters = 1) ⇒ Object
Read lines until we match regexp iters times. If a block is given, each line is sent to that block until the block returns true iters times.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rgnuchess.rb', line 34 def gets_until( regexp=//, iters=1 ) match_test = lambda do |str| if block_given? yield(str) else regexp=~str end end count=0 result = [] begin str = self.gets result << str end until match_test.call(str) && (count+=1)==iters return result end |