Created
November 23, 2012 03:55
-
-
Save bradylove/4133949 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pry' | |
| require './sample' | |
| require 'ruby_parser' | |
| require 'sexp_processor' | |
| class Parser < SexpProcessor | |
| def initalize | |
| super | |
| self.strict = false | |
| end | |
| def process_list(exp) | |
| val = exp.shift | |
| return val | |
| end | |
| end | |
| module Doctor | |
| @@klass = nil | |
| @@description = nil | |
| @@method_name = nil | |
| def doctor(klass) | |
| @@klass = klass.new | |
| path = "sample.rb" | |
| @@code = File.read(path) | |
| @@sexp = RubyParser.new.parse(@@code, path) | |
| @@parser = Parser.new | |
| @@parsed = @@parser.process(@@sexp) | |
| yield | |
| end | |
| def doc(method_name, &block) | |
| yield block | |
| @@method_name = method_name | |
| puts "#{@@klass.class.to_s}##{@@method_name.to_s} : Line #{source_line}" | |
| puts @@description | |
| puts @@arguments.to_s | |
| puts "" | |
| end | |
| def source_line | |
| @@klass.method(@@method_name).source_location[1] | |
| end | |
| def method_name | |
| @@method_name | |
| end | |
| def method_name=(method_name) | |
| @@method_name = method_name | |
| end | |
| def description(description) | |
| @@description = description | |
| end | |
| def arguments(arguments) | |
| @@arguments = arguments | |
| end | |
| end | |
| include Doctor | |
| doctor Sample do | |
| doc :to_string do |x| | |
| description "Outputs String \"Hello string!\"" | |
| arguments [] | |
| end | |
| doc :poopy_pants do |x| | |
| description "Makes your pants very poopy" | |
| arguments ['farts', 'smell'] | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment