Top Level Namespace
Defined Under Namespace
Modules: Ask
Instance Method Summary collapse
- #capture_output ⇒ Object
- #read_frame ⇒ Object
- #safe_inspect(value) ⇒ Object
- #write_frame(frame) ⇒ Object
Instance Method Details
#capture_output ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ask/tools/shell/repl/kernel_script.rb', line 38 def capture_output old_out = $stdout old_err = $stderr out = StringIO.new err = StringIO.new $stdout = out $stderr = err yield [out.string, err.string] ensure $stdout = old_out $stderr = old_err end |
#read_frame ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/ask/tools/shell/repl/kernel_script.rb', line 24 def read_frame line = $stdin.gets return nil if line.nil? JSON.parse(line) rescue JSON::ParserError { "error" => "invalid request frame" } end |
#safe_inspect(value) ⇒ Object
52 53 54 55 56 |
# File 'lib/ask/tools/shell/repl/kernel_script.rb', line 52 def safe_inspect(value) value.inspect rescue StandardError "#<#{value.class}>" end |
#write_frame(frame) ⇒ Object
33 34 35 36 |
# File 'lib/ask/tools/shell/repl/kernel_script.rb', line 33 def write_frame(frame) $stdout.puts(JSON.generate(frame)) $stdout.flush end |