Class: Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/troshka/editor/shell.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShell

Returns a new instance of Shell.



6
7
8
9
# File 'lib/troshka/editor/shell.rb', line 6

def initialize
  @binding = TOPLEVEL_BINDING
  $stdout = StringIO.new
end

Instance Attribute Details

#resultObject

Returns the value of attribute result.



4
5
6
# File 'lib/troshka/editor/shell.rb', line 4

def result
  @result
end

Instance Method Details

#run(str) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/troshka/editor/shell.rb', line 11

def run(str)
  result = eval(str, @binding, "(troshka)")
  ::Troshka::App.last_result = result
  eval("_ = Troshka::App.last_result", @binding)

  exception = nil

  $stdout.rewind
  output = $stdout.read
  $stdout.truncate(0)
  $stdout.rewind
rescue Exception => e
  output = nil
  obj = nil
  exception = e
ensure
  return {code: str, output: output, obj: result, exception: exception}
end