Class: Rereline::Debugger

Inherits:
Object
  • Object
show all
Defined in:
lib/rereline/debugger.rb

Defined Under Namespace

Modules: Refine

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Debugger

Returns a new instance of Debugger.



3
4
5
# File 'lib/rereline/debugger.rb', line 3

def initialize(output)
  @output = output
end

Instance Method Details

#debug(*args, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/rereline/debugger.rb', line 11

def debug(*args, &block)
  if block
    node = RubyVM::AbstractSyntaxTree.of(block, keep_script_lines: true)
    code = node.children.last.source
    puts "#{code} => #{block.binding.eval(code).inspect}"
  else
    puts(*args)
  end
end

#puts(*args) ⇒ Object



7
8
9
# File 'lib/rereline/debugger.rb', line 7

def puts(*args)
  @output&.puts(*args)
end