Class: IO
Instance Method Summary collapse
- #binread(file, *arg) ⇒ Object
-
#bytes ⇒ Object
Standard in ruby 1.8.7+.
-
#chars ⇒ Object
Standard in ruby 1.8.7+.
-
#each_char ⇒ Object
Standard in ruby 1.8.7+.
-
#lines(*args) ⇒ Object
Standard in ruby 1.8.7+.
Instance Method Details
#binread(file, *arg) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/backports/1.9/io.rb', line 3 def binread(file, *arg) raise ArgumentError, "wrong number of arguments (#{1+arg.size} for 1..3)" unless arg.size < 3 File.open(Backports.convert_to_path(file),"rb") do |f| f.read(*arg) end end |
#bytes ⇒ Object
Standard in ruby 1.8.7+. See official documentation
10 11 12 |
# File 'lib/backports/1.8.7/io.rb', line 10 def bytes to_enum :each_byte end |
#chars ⇒ Object
Standard in ruby 1.8.7+. See official documentation
15 16 17 |
# File 'lib/backports/1.8.7/io.rb', line 15 def chars to_enum :each_char end |
#each_char ⇒ Object
Standard in ruby 1.8.7+. See official documentation
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/backports/1.8.7/io.rb', line 20 def each_char return to_enum(:each_char) unless block_given? if $KCODE == "UTF-8" lookup = 7.downto(4) while c = read(1) do n = c[0] leftmost_zero_bit = lookup.find{|i| n[i].zero? } case leftmost_zero_bit when 7 # ASCII yield c when 6 # UTF 8 complementary characters next # Encoding error, ignore else more = read(6-leftmost_zero_bit) break unless more yield c+more end end else while s = read(1) yield s end end self end |
#lines(*args) ⇒ Object
Standard in ruby 1.8.7+. See official documentation
51 52 53 |
# File 'lib/backports/1.8.7/io.rb', line 51 def lines(*args) to_enum :each_line, *args end |