Class: RemoteRuby::SourceExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_ruby/source_extractor.rb

Overview

Receives a block and extracts Ruby code (as a string) with this block's source

Instance Method Summary collapse

Instance Method Details

#extract(&block) ⇒ Object


9
10
11
12
13
14
15
16
17
# File 'lib/remote_ruby/source_extractor.rb', line 9

def extract(&block)
  ast = Parser::CurrentRuby.parse(block.source)
  block_node = find_block(ast)

  return '' unless block_node

  _, body = parse(block_node)
  Unparser.unparse(body)
end