Sha256: 1fc95aa85525c3e86f6e840220baa4b7e1f6589a97532e7e787c5761b3030321

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

class IO
  SEEK_SET = 0
  SEEK_CUR = 1
  SEEK_END = 2

  module Writable
    def <<(string)
      write(string)

      self
    end

    def print(*args)
      write args.map { |arg| String(arg) }.join($,)
    end

    def puts(*args)
      write args.map { |arg| String(arg) }.join($/)
    end
  end

  module Readable
    def readbyte
      getbyte
    end

    def readchar
      getc
    end

    def readline(sep = $/)
      raise NotImplementedError
    end

    def readpartial(integer, outbuf = nil)
      raise NotImplementedError
    end
  end
end

STDERR = $stderr = IO.new
STDIN  = $stdin  = IO.new
STDOUT = $stdout = IO.new

def $stdout.puts(*strs)
  %x{
    for (var i = 0; i < strs.length; i++) {
      if (strs[i] instanceof Array) {
        #{puts(*`strs[i]`)};
      }
      else {
        console.log(#{`strs[i]`.to_s});
      }
    }
  }

  nil
end

def $stderr.puts(*strs)
  %x{
    for (var i = 0; i < strs.length; i++) {
      if (strs[i] instanceof Array) {
        #{puts(*`strs[i]`)};
      }
      else {
        console.warn(#{`strs[i]`.to_s});
      }
    }
  }

  nil
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opal-0.5.5 opal/corelib/io.rb
opal-0.5.4 opal/core/io.rb
opal-0.5.2 opal/core/io.rb