Class: VirtualKeywords::SexpStringifier

Inherits:
Object
  • Object
show all
Defined in:
lib/virtual_keywords/sexp_stringifier.rb

Overview

Class that turns a sexp back into a string of Ruby code.

Instance Method Summary collapse

Constructor Details

#initialize(unifier = Unifier.new, ruby2ruby = Ruby2Ruby.new) ⇒ SexpStringifier

Initialize the SexpStringifier

Arguments:

unifier: (Unifier) a Unifier, used by ParseTree/ruby2ruby (optional)
ruby2ruby: (Ruby2Ruby) a Ruby2Ruby, used by ParseTree/ruby2ruby
           (optional)


10
11
12
13
# File 'lib/virtual_keywords/sexp_stringifier.rb', line 10

def initialize(unifier = Unifier.new, ruby2ruby = Ruby2Ruby.new)
  @unifier = unifier
  @ruby2ruby = ruby2ruby
end

Instance Method Details

#stringify(sexp) ⇒ Object

Turn a sexp into a string of Ruby code. Makes a copy first so the inputted sexp is not emptied.

Arguments:

sexp: (Sexp) the sexp to be stringified.

Returns:

(String) Ruby code equivalent to the sexp.


23
24
25
26
# File 'lib/virtual_keywords/sexp_stringifier.rb', line 23

def stringify sexp
  sexp_copy = VirtualKeywords.deep_copy_array sexp
  @ruby2ruby.process(@unifier.process(sexp_copy))
end