module LiveAST::RubyParser::Test
Public Class Methods
Whether this is Ryan Davis's unified sexp format.
# File lib/live_ast/ruby_parser/test.rb, line 13 def unified_sexp? true end
Whether the unparser output matches that of ruby2ruby.
# File lib/live_ast/ruby_parser/test.rb, line 20 def unparser_matches_ruby2ruby? true end
Public Instance Methods
binop_block
(:foo, :+) returns the ast of
foo { |x, y| x + y }
# File lib/live_ast/ruby_parser/test.rb, line 146 def binop_block(name, op) s(:iter, s(:call, nil, name), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end
binop_def
(:f, :+) returns the ast of
def f(x, y) x + y end
# File lib/live_ast/ruby_parser/test.rb, line 61 def binop_def(name, op) s(:defn, name, s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end
binop_define_method
(:f, :*) returns the ast of
define_method :f do |x, y| x * y end
binop_define_method
(:f, :-, :my_def) returns the ast of
my_def :f do |x, y| x - y end
# File lib/live_ast/ruby_parser/test.rb, line 96 def binop_define_method(name, op, using = :define_method) s(:iter, s(:call, nil, using, s(:lit, name)), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end
binop_define_method_with_var
(:method_name, :/) returns the ast of
define_method method_name do |x, y| x / y end
# File lib/live_ast/ruby_parser/test.rb, line 110 def binop_define_method_with_var(var_name, op) s(:iter, s(:call, nil, :define_method, s(:lvar, var_name)), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end
binop_define_singleton_method
(:f, :+, :a) returns the ast of
a.define_singleton_method :f do |x, y| x + y end
# File lib/live_ast/ruby_parser/test.rb, line 124 def binop_define_singleton_method(name, op, receiver) s(:iter, s(:call, s(:lvar, receiver), :define_singleton_method, s(:lit, name)), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end
binop_lambda
(:+) returns the ast of
lambda { |x, y| x + y }
# File lib/live_ast/ruby_parser/test.rb, line 158 def binop_lambda(op) s(:iter, s(:lambda), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end
binop_proc_new
(:*) returns the ast of
Proc.new { |x, y| x * y }
# File lib/live_ast/ruby_parser/test.rb, line 170 def binop_proc_new(op) s(:iter, s(:call, s(:const, :Proc), :new), s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end
nested_defs
(:f, :g, “foo”) returns the ast of
def f Class.new do def g "foo" end end end
# File lib/live_ast/ruby_parser/test.rb, line 203 def nested_defs(u, v, str) s(:defn, u, s(:args), s(:iter, s(:call, s(:const, :Class), :new), 0, s(:defn, v, s(:args), s(:str, str)))) end
nested_lambdas
(“foo”) returns the ast of
lambda { lambda { "foo" } }
# File lib/live_ast/ruby_parser/test.rb, line 186 def nested_lambdas(str) s(:iter, s(:call, nil, :lambda), 0, s(:iter, s(:call, nil, :lambda), 0, s(:str, str))) end
no_arg_block
(:foo, “bar”) returns the ast of
foo { "bar" }
# File lib/live_ast/ruby_parser/test.rb, line 137 def no_arg_block(name, ret) s(:iter, s(:call, nil, name), 0, s(:str, ret)) end
no_arg_def
(:f, “A#f”) returns the ast of
def f "A#f" end
# File lib/live_ast/ruby_parser/test.rb, line 32 def no_arg_def(name, ret) s(:defn, name, s(:args), s(:str, ret)) end
no_arg_def_return
(no_arg_def
(:f, “A#f”)) == “A#f”
# File lib/live_ast/ruby_parser/test.rb, line 50 def no_arg_def_return(ast) ast[3][1] end
singleton_binop_def
(:A, :f, :+) returns the ast of
def A.f(x, y) x + y end
# File lib/live_ast/ruby_parser/test.rb, line 75 def singleton_binop_def(const, name, op) s(:defs, s(:const, const), name, s(:args, :x, :y), s(:call, s(:lvar, :x), op, s(:lvar, :y))) end
singleton_no_arg_def
(:f, “foo”) returns the ast of
def self.f "foo" end
# File lib/live_ast/ruby_parser/test.rb, line 43 def singleton_no_arg_def(name, ret) s(:defs, s(:self), name, s(:args), s(:str, ret)) end