Skip to content

Instantly share code, notes, and snippets.

@numinit
Created September 18, 2012 17:37
Show Gist options
  • Save numinit/3744525 to your computer and use it in GitHub Desktop.
Save numinit/3744525 to your computer and use it in GitHub Desktop.
module Kernel
def std
@@std ||= Module.new do
def ios
Module.new do
def ios
@@ios ||= Class.new do
def initialize stream
@stream = stream
end
end
end
end
end
def istream
Module.new do
include std::ios
def istream
@@istream ||= Class.new(std::ios) do
def initialize stream
super stream
end
def get
@stream.read
end
end
end
end
end
def ostream
Module.new do
include std::ios
def ostream
@@ostream ||= Class.new(std::ios) do
def initialize stream
super stream
end
def << rhs
@stream.write rhs
self
end
end
end
end
end
def iostream
Module.new do
include std::istream
include std::ostream
def cout
@@cout ||= std::ostream.new(STDOUT)
end
def cerr
@@cerr ||= std::ostream.new(STDERR)
end
def cin
@@cin ||= std::istream.new(STDIN)
end
def endl
"\n"
end
end
end
end
end
end
include std
@lukateras
Copy link

What have you done?.. :-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment