Class: VirtualKeywords::ClassMirrorer

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

Overview

ClassMirrorer that uses ParseTree (Ruby 1.8)

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ClassMirrorer

Initialize a ParseTreeClassMirrorer

Arguments:

An options Hash with the following key
  parser: (ParserStrategy) an object with a method translate, that takes
      a class and method name, and returns a syntax tree that can be
      sexpified (optional, the default is ParserStrategy.new)


14
15
16
# File 'lib/virtual_keywords/class_mirrorer.rb', line 14

def initialize options
  @parser = options[:parser] || ParserStrategy.new
end

Instance Method Details

#mirror(klass) ⇒ Object

Map ClassAndMethodNames to sexps

Arguments:

klass: (Class) the class to mirror.

Returns:

(Hash[ClassAndMethodName, Sexp]) a hash mapping every method of the
class to parsed output.


26
27
28
29
30
31
32
33
34
35
# File 'lib/virtual_keywords/class_mirrorer.rb', line 26

def mirror klass
  methods = {}
  klass.instance_methods(false).each do |method_name|
    key = ClassAndMethodName.new(klass, method_name)
    translated = @parser.translate_instance_method(klass, method_name)
    methods[key] = translated
  end

  methods
end