Module: IRuby::History

Included in:
PlainBackend, PryBackend
Defined in:
lib/iruby/backend.rb

Instance Method Summary collapse

Instance Method Details

#eval(code, store_history) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/iruby/backend.rb', line 6

def eval(code, store_history)
  b = TOPLEVEL_BINDING

  b.local_variable_set(:_ih, In)  unless b.local_variable_defined?(:_ih)
  b.local_variable_set(:_oh, Out) unless b.local_variable_defined?(:_oh)

  out = super

  # TODO Add IRuby.cache_size which controls the size of the Out array
  # and sets the oldest entries and _<n> variables to nil.
  if store_history
    b.local_variable_set("_#{Out.size}", out)
    b.local_variable_set("_i#{In.size}", code)

    Out << out
    In << code

    b.local_variable_set(:___,  Out[-3])
    b.local_variable_set(:__,   Out[-2])
    b.local_variable_set(:_,    Out[-1])
    b.local_variable_set(:_iii, In[-3])
    b.local_variable_set(:_ii,  In[-2])
    b.local_variable_set(:_i,   In[-1])
  end

  out
end