Module: LiveAST

Defined in:
lib/live_ast/ruby_parser/test.rb,
lib/live_ast/base.rb,
lib/live_ast/error.rb,
lib/live_ast/common.rb,
lib/live_ast/evaler.rb,
lib/live_ast/linker.rb,
lib/live_ast/loader.rb,
lib/live_ast/reader.rb,
lib/live_ast/to_ast.rb,
lib/live_ast/irb_spy.rb,
lib/live_ast/to_ruby.rb,
lib/live_ast/version.rb,
lib/live_ast/ruby_parser.rb,
lib/live_ast/replace_eval.rb,
lib/live_ast/ruby_parser/unparser.rb

Overview

Used by to_ruby in LiveAST.

Defined Under Namespace

Modules: Attacher, CallableToRuby, Common, Evaler, IRBSpy, Linker, Loader, MethodToAST, ProcToAST, Reader, ReplaceEval Classes: ASTNotFoundError, Cache, MultipleDefinitionsOnSameLineError, RawEvalError, RubyParser

Constant Summary collapse

NATIVE_EVAL =

:nodoc:

Kernel.method(:eval)
VERSION =
"2.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.parserObject

:nodoc:



17
18
19
20
21
22
23
# File 'lib/live_ast/base.rb', line 17

def parser # :nodoc:
  @parser ||=
    begin
      require "live_ast/ruby_parser"
      LiveAST::RubyParser
    end
end

Class Method Details

.ast(obj) ⇒ Object

For use in noninvasive mode (require 'live_ast/base').

Equivalent to obj.to_ast.



30
31
32
33
34
35
36
37
38
39
# File 'lib/live_ast/base.rb', line 30

def ast(obj) # :nodoc:
  case obj
  when Method, UnboundMethod
    Linker.find_method_ast(obj.owner, obj.name, *obj.source_location)
  when Proc
    Linker.find_proc_ast(obj)
  else
    raise TypeError, "No AST for #{obj.class} objects"
  end
end

.eval(string, bind, filename = nil, lineno = nil) ⇒ Object

For use in noninvasive mode (require 'live_ast/base').

Equivalent to Kernel#ast_eval.



54
55
56
# File 'lib/live_ast/base.rb', line 54

def eval(string, bind, filename = nil, lineno = nil) # :nodoc:
  Evaler.eval(string, string, bind, filename, lineno)
end

.flush_cacheObject

Flush unused ASTs from the cache. See README.rdoc before doing this.



45
46
47
# File 'lib/live_ast/base.rb', line 45

def flush_cache
  Linker.flush_cache
end

.load(file, wrap = false) ⇒ Object

For use in noninvasive mode (require 'live_ast/base').

Equivalent to Kernel#ast_load.



63
64
65
# File 'lib/live_ast/base.rb', line 63

def load(file, wrap = false) # :nodoc:
  Loader.load(file, wrap)
end

.strip_token(file) ⇒ Object

strip the revision token from a string



70
71
72
# File 'lib/live_ast/base.rb', line 70

def strip_token(file) # :nodoc:
  file.sub(/#{Regexp.quote Linker::REVISION_TOKEN}[a-z]+/, "")
end