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/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, ObjectAndKeyword, OrRewriter, RewriteLambdaNotProvided, RewrittenKeywords, SexpStringifier, Virtualizer

Constant Summary collapse

VERSION =
'0.0.0'
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.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/virtual_keywords/keyword_rewriter.rb', line 53

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) the array to copy. A is any arbitrary type.

Returns: (Array) a deep copy of the original array.



94
95
96
# File 'lib/virtual_keywords/virtualizer.rb', line 94

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

.sanity_testObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/virtual_keywords.rb', line 18

def self.sanity_test
  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