Class | IO |
In: |
lib/backports/1.9.1/io.rb
lib/backports/1.8.7/io.rb lib/backports/1.9.3/io.rb |
Parent: | Object |
ungetbyte | -> | self |
bytes | -> | self |
chars | -> | self |
lines | -> | self |
getbyte | -> | self |
readbyte | -> | self |
# File lib/backports/1.9.1/io.rb, line 3 3: def binread(file, *arg) 4: raise ArgumentError, "wrong number of arguments (#{1+arg.size} for 1..3)" unless arg.size < 3 5: File.open(Backports.convert_to_path(file),"rb") do |f| 6: f.read(*arg) 7: end 8: end
Standard in Ruby 1.9.3 See official documentation This method does support an options hash, see bugs.ruby-lang.org/issues/5782
# File lib/backports/1.9.3/io.rb, line 29 29: def binwrite(name, string, offset = nil, options = Backports::Undefined) 30: Backports.write(true, name, string, offset, options) 31: end
# File lib/backports/1.9.1/io.rb, line 17 17: def open_with_options_hash(fd, mode = nil, options = Backports::Undefined) 18: mode = Backports.combine_mode_and_option(mode, options) 19: # Can't backport autoclose, {internal|external|}encoding 20: if block_given? 21: open_without_options_hash(fd, mode){|f| yield f} 22: else 23: open_without_options_hash(fd, mode) 24: end 25: end
# File lib/backports/1.9.1/io.rb, line 10 10: def try_convert(obj) 11: Backports.try_convert(obj, IO, :to_io) 12: end
Standard in Ruby 1.9.3 See official documentation
# File lib/backports/1.9.3/io.rb, line 23 23: def write(name, string, offset = nil, options = Backports::Undefined) 24: Backports.write(false, name, string, offset, options) 25: end
Standard in Ruby 1.9.3 See official documentation We‘re only for a platform not implementing advise, so we return nil.
# File lib/backports/1.9.3/io.rb, line 4 4: def advise(advice, offset=0, len=0) 5: case advice 6: when :normal, 7: :sequential, 8: :random, 9: :willneed, 10: :dontneed, 11: :noreuse 12: return nil 13: when Symbol 14: raise NotImplementedError, "Unsupported advice #{advice}" 15: else 16: raise TypeError, "advice must be a Symbol" 17: end 18: end
# File lib/backports/1.8.7/io.rb, line 9 9: def each_char 10: return to_enum(:each_char) unless block_given? 11: if $KCODE == "UTF-8" 12: lookup = 7.downto(4) 13: while c = read(1) do 14: n = c[0] 15: leftmost_zero_bit = lookup.find{|i| n[i].zero? } 16: case leftmost_zero_bit 17: when 7 # ASCII 18: yield c 19: when 6 # UTF 8 complementary characters 20: next # Encoding error, ignore 21: else 22: more = read(6-leftmost_zero_bit) 23: break unless more 24: yield c+more 25: end 26: end 27: else 28: while s = read(1) 29: yield s 30: end 31: end 32: 33: self 34: end