Module: VirtualKeywords

Defined in:
lib/virtual_keywords/virtualizer.rb,
lib/virtual_keywords.rb,
lib/virtual_keywords/version.rb,
lib/virtual_keywords/class_mirrorer.rb,
lib/virtual_keywords/deep_copy_array.rb,
lib/virtual_keywords/parser_strategy.rb,
lib/virtual_keywords/class_reflection.rb,
lib/virtual_keywords/keyword_rewriter.rb,
lib/virtual_keywords/sexp_stringifier.rb,
lib/virtual_keywords/rewritten_keywords.rb

Overview

Parent module containing all variables defined as part of virtual_keywords

Defined Under Namespace

Classes: AndRewriter, ClassAndMethodName, ClassMirrorer, ClassReflection, Foo, IfRewriter, NoSuchClass, NoSuchInstance, NotRewriter, ObjectAndKeyword, OrRewriter, ParseTreeStrategy, ParserStrategy, RewriteLambdaNotProvided, RewrittenKeywords, RubyParserStrategy, SexpStringifier, UnexpectedSexp, UntilRewriter, Virtualizer, WhileRewriter

Constant Summary collapse

VERSION =
'0.3.1'
REWRITTEN_KEYWORDS =

The global instance of RewrittenKeywords that will be used. I don’t normally like using global variables, but in this case we need a global point of access, because we can’t always control the scope in which methods are executed.

RewrittenKeywords.new({})

Class Method Summary collapse

Class Method Details

.call_operator_replacement(function_name, first, second) ⇒ Object

Helper method. Call a 2-argument function used to replace an operator (like “and” or “or”)

Arguments:

method_name: (Symbol) the name of the REWRITTEN_KEYWORDS method that
    should be called in the sexp.
first: (Sexp) the first argument to the method, which should be
    wrapped in a lambda then passed to REWRITTEN_KEYWORDS. 
second: (Sexp) the second argument to the method, which should be
    wrapped in a lambda then passed to REWRITTEN_KEYWORDS.


59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/virtual_keywords/keyword_rewriter.rb', line 59

def self.call_operator_replacement(function_name, first, second)
  s(:call,
    s(:colon2,
      s(:const, :VirtualKeywords),
      :REWRITTEN_KEYWORDS
    ), function_name,
    s(:array,
      s(:self),
      s(:iter, s(:fcall, :lambda), nil, first),
      s(:iter, s(:fcall, :lambda), nil, second)
    )
  )
end

.deep_copy_array(array) ⇒ Object

Deeply copy an array.

Arguments:

array: (Array[A]) the array to copy. A is any arbitrary type.

Returns:

(Array[A]) a deep copy of the original array.


9
10
11
# File 'lib/virtual_keywords/deep_copy_array.rb', line 9

def self.deep_copy_array(array)
  Marshal.load(Marshal.dump(array))
end

.sanity_testObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/virtual_keywords.rb', line 44

def self.sanity_test
  # TODO See if there's a way to run the specs instead of this, when
  # building the gem and requiring it
  virtualizer = Virtualizer.new(
      :for_classes => [Foo]
  )
  virtualizer.virtual_if do |condition, then_do, else_do|
    :pwned
  end

  foo = Foo.new
  if foo.hi == :pwned
    :success
  else
    :failure
  end
end