Module: LiveAST::IRBSpy

Defined in:
lib/live_ast/irb_spy.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.history=(value) ⇒ Object (writeonly)

Sets the attribute history

Parameters:

  • value

    the value to set the attribute history to.



7
8
9
# File 'lib/live_ast/irb_spy.rb', line 7

def history=(value)
  @history = value
end

Class Method Details

.code_at(line) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/live_ast/irb_spy.rb', line 9

def code_at(line)
  unless @history
    raise NotImplementedError,
    "LiveAST cannot access history for this IRB input method"
  end
  grow = 0
  begin
    code = @history[line..(line + grow)].join
    LiveAST.parser.new.parse(code) or raise "#{LiveAST.parser} error"
  rescue
    grow += 1
    retry if line + grow < @history.size
    raise
  end
  code
end